Skip to content

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

Open
@daboross

Description

@daboross

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?

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions