servo / servo/rust-url

Extend query parameters with Display types rather than &str?

Open
#348 2 comments 0 reactions 1 assignee View on GitHub

@nox is already working on this.

Since Jul 18, 2019.

breaking-change
Dominant language
Rust
Stars
1.6k
Forks
406
PR merge metrics
No merged PRs in 30d

Description

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 (https://github.com/servo/rust-url/blob/e461e347cc0c078ca101f8d4fcc7d4df9d925eef/src/form_urlencoded.rs#L360) 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?

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.