Skip to content

Extend query parameters with Display types rather than &str? #348

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

Open
daboross opened this issue May 23, 2017 · 2 comments
Open

Extend query parameters with Display types rather than &str? #348

daboross opened this issue May 23, 2017 · 2 comments
Assignees

Comments

@daboross
Copy link

daboross commented May 23, 2017

Hi!

I was wondering if url had any plans to add more support for not allocating intermediate strings, especially when adding query parameters. Right now, &str is needed in order to pass to a parameter, so if I have the data represented as anything else (like a stack allocated endpoint-specific type), I have to allocate an extra string per query parameter every time I create a new URL.

Would it be within the scope of url to add support for arbitrary Display types to Serializer::append_pair?

It seems this method (

fn append_pair(string: &mut String, start_position: usize, encoding: EncodingOverride,
) just directly pushes these &str values to the string anyways, so I think it would be completely feasible to support Display types here, and just use write!() instead.

I'm guessing this wouldn't be possible at all to use if EncodingOverride was enabled, since the encoding crate seems to operate completely on string slices as well, but it would be a much more efficient option when it wasn't enabled.

If this is within the scope of url, I'd be willing to spend some time implementing it - I would at least think it would be useful to not do additional allocations for each url query.

Then again, maybe this would just be a useless micro-optimization. I don't know enough about the internals of url to know whether this is in scope, so I'll just leave this open for more seasoned contributor comments, if any?

@nox
Copy link
Contributor

nox commented Jul 18, 2019

This is something that would improve performance in serde_urlencoded too.

@nox nox self-assigned this Jul 18, 2019
@djc
Copy link
Contributor

djc commented Aug 26, 2020

I don't think this would be a breaking change to take T: Display, since &str also implements Display, right?

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

No branches or pull requests

3 participants