Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Serialize vectors without indices #115

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open

Conversation

tjardoo
Copy link

@tjardoo tjardoo commented Nov 26, 2024

This is a proof of concept to serialize a vector without indices in the query string user_ids[]=100&user_ids[]=101. The default is using indices user_ids[0]=100&user_ids[1]=101. The structure without the indices is used by ie. the OpenAI API.

I added a new method to_string_config(input, config) to be able to serialize with a custom configuration. The existing method to_string(input) will work the same as before and will use the default config (using indices).

The new config currently only has the field use_indices of type boolean - but can be expanded later if needed.

I'm not really a fan of using two different methods, do you have any suggestion on how you would like this to work? @samscott89
As there is no standard for this type of serialization - if you do not want to support this, feel free to close it. Thanks.

let params = QueryParams {
    id: 42,
    user_ids: vec![1, 2, 3, 4],
};

let config = SerializerConfig { use_indices: false };

assert_eq!(
    serde_qs::to_string_config(&params, config).unwrap(),
    "\
    id=42&user_ids[]=1&user_ids[]=2&\
    user_ids[]=3&user_ids[]=4"
);

@tjardoo tjardoo marked this pull request as ready for review November 26, 2024 13:32
@tjardoo
Copy link
Author

tjardoo commented Nov 26, 2024

Resolves #80

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant