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

Option to serialize Vec<T> into comma-separated list #13

Closed
Salzian opened this issue Oct 10, 2022 · 4 comments
Closed

Option to serialize Vec<T> into comma-separated list #13

Salzian opened this issue Oct 10, 2022 · 4 comments

Comments

@Salzian
Copy link

Salzian commented Oct 10, 2022

This would be nice for APIs that require a comma-separated list for authorization scopes.

I was looking into the source code myself, but I only have limited knowledge of the inner workings of serde. Not sure where a Vec is being iterated in the custom Serializer of this crate.

@boxdot
Copy link
Owner

boxdot commented Oct 11, 2022

Do you an example of how it should be used with an expected output? We could make it directly into a test and implement it.

@Salzian
Copy link
Author

Salzian commented Oct 11, 2022

Here's an example where I wanted to use this crate for generating an OAuth url for Google Calendars:

#[derive(Serialize)]
pub(crate) struct AuthorizationParameters<'a> {
    ...
    scope: Vec<&'a str>,
    ...
}

Actual

scope=openid&scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fcalendar.events.owned.readonly

Needed

scope=openid,https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fcalendar.events.owned.readonly

@boxdot
Copy link
Owner

boxdot commented Oct 11, 2022

I added an example in #14. Does it solve you problem?

https://github.com/boxdot/serde-url-params-rs/pull/14/files#diff-fbd250710bab29e09d41e0c500aca98633826a0f71a8a354659bc27476756093

@Salzian
Copy link
Author

Salzian commented Oct 17, 2022

Sorry for the delay, I was enjoying the rest of my holidays.

In my quick tinkering, I failed to implement this for my use case. After looking at it again at a later time, I noticed the usage of the Itertools crate. Seems like the format functionality "is" experimental in std (slice_concat_trait). Actually it's stable but seems like they forgot to remove the annotations.

Either way, with your guidance on how to operate the serde crate in this example, I think I can either replicate the behaviour with some custom implementation or I consider using Itertools.

Thanks!

Not sure if I should close this issue now or if you want to link-close it with #14.

@Salzian Salzian closed this as not planned Won't fix, can't repro, duplicate, stale Nov 28, 2022
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

No branches or pull requests

2 participants