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

Add url search params #57

Merged
merged 13 commits into from
Dec 3, 2024
Merged

Add url search params #57

merged 13 commits into from
Dec 3, 2024

Conversation

anonrig
Copy link
Member

@anonrig anonrig commented Nov 25, 2023

Some traits are missing. Since I'm not using Rust daily, I don't know which traits are beneficial to be implemented into the new structs.

Please review and give recommendations around the missing structs and the API surface.

@anonrig anonrig force-pushed the add-url-search-params branch 4 times, most recently from cb742ba to 4816774 Compare November 25, 2023 18:46
@anonrig anonrig marked this pull request as ready for review November 28, 2023 01:48
@anonrig anonrig force-pushed the add-url-search-params branch from 4816774 to ac2efd0 Compare December 1, 2024 16:48
Copy link

@untitaker untitaker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

src/url_search_params.rs Outdated Show resolved Hide resolved
src/url_search_params.rs Outdated Show resolved Hide resolved
src/url_search_params.rs Outdated Show resolved Hide resolved
src/url_search_params.rs Outdated Show resolved Hide resolved
src/url_search_params.rs Outdated Show resolved Hide resolved
src/url_search_params.rs Outdated Show resolved Hide resolved
src/url_search_params.rs Outdated Show resolved Hide resolved
src/ffi.rs Show resolved Hide resolved
Copy link
Collaborator

@Swatinem Swatinem left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with all the points @untitaker has raised.

As suggested, I would also auto-generate the C(++)?-ffi bindings.

Then, I would make all mutating methods &mut self.

For strings, it might be worth converting those to either &CStr or &str at the FFI boundary, depending on what bindgen it doing.

src/url_search_params.rs Outdated Show resolved Hide resolved
src/url_search_params.rs Outdated Show resolved Hide resolved
src/url_search_params.rs Outdated Show resolved Hide resolved
src/url_search_params.rs Outdated Show resolved Hide resolved
@anonrig anonrig force-pushed the add-url-search-params branch from b9811ac to 2ab1c7f Compare December 1, 2024 23:37
@anonrig
Copy link
Member Author

anonrig commented Dec 1, 2024

hey @untitaker @Swatinem @mitsuhiko, thank you for all the reviews! I've tried to address them all, and learned a lot along the way. Would you mind taking a one last take? Please nit-pick / be super-picky, and don't lower your personal barrier (just for the sake of positivity).

Copy link
Collaborator

@Swatinem Swatinem left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm, though some more polish would be needed:

  • which length are we talking about? length in serialized bytes? number of unique keys? number of total values?
  • it should be made clearer in docs, and maybe also in the types how exactly the multi-map works.

So this means clarifying and maybe also giving an example for accessors that yield the first value, vs those that yield all the values. For example, does entries() give you just the first value, or does it rather give you the same key multiple times with each of its values?

Same for the remove and contains method, please clarify how the Option-al value relates to the multi-map.

looking up MultiMap on crates/docs.rs gave me this crate which has for example iter that yields keys and their first value, plus flat_iter which I believe would duplicate keys for each value, though I believe the docs are also wrong/unclear there: https://docs.rs/multimap/latest/multimap/struct.MultiMap.html#method.flat_iter

Another question related rather to URLs would be whether a value-less key is even valid? Like ?a&b&c?

src/url_search_params.rs Show resolved Hide resolved
src/url_search_params.rs Outdated Show resolved Hide resolved
src/url_search_params.rs Outdated Show resolved Hide resolved
Comment on lines +248 to +250
impl<Input> Extend<(Input, Input)> for UrlSearchParams
where
Input: AsRef<str>,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could use two different generics here, that way you could use a &str, Cow<'_, str> or whatever other combination of key/value types, instead of being forced into using the same type for key/value.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the syntax for supporting multiple generics for the same variable?

src/url_search_params.rs Show resolved Hide resolved
Copy link
Contributor

@steveklabnik steveklabnik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this looks good overall, left some comments, mostly style things.

src/ffi.rs Show resolved Hide resolved
length: usize,
) -> *mut ada_url_search_params;
pub fn ada_free_search_params(search_params: *mut ada_url_search_params);
pub fn ada_search_params_size(search_params: *mut ada_url_search_params) -> usize;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, on the -> usize bit here, this isn't wrong but it is something that's like, being debated. That is, if usize is size_t or not. Today, it's often used that way, but this can cause issues on platforms like CHERI. However, there's tons of code written like this, so anything that happens will have to deal with all of that... so I'm not saying you shouldn't do this, just wanted to clue you in on that as a general thing.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I remember reading about this. Nice catch. What's the "best" solution to use for usize?

src/url_search_params.rs Show resolved Hide resolved
src/url_search_params.rs Show resolved Hide resolved
src/url_search_params.rs Outdated Show resolved Hide resolved
src/url_search_params.rs Outdated Show resolved Hide resolved
src/url_search_params.rs Outdated Show resolved Hide resolved
src/url_search_params.rs Outdated Show resolved Hide resolved
src/url_search_params.rs Outdated Show resolved Hide resolved
src/url_search_params.rs Outdated Show resolved Hide resolved
@anonrig anonrig merged commit d0b2219 into main Dec 3, 2024
6 checks passed
@anonrig anonrig deleted the add-url-search-params branch December 3, 2024 20:29
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.

5 participants