Skip to content

take ToString instead of Into<String> #2

@laralove143

Description

@laralove143

the methods in this library, namely with(_opt)?_value and push(_opt)? methods of QueryString take strings as Into<String> rather than ToString, changing them to take implementors of ToString would allow people to pass types implementing Display

while i can agree that sometimes a type can implement both Display and Into<String> i think it is rare, i've never seen a type implementing From<T> for String so i think it is kind of an anti-pattern

i think taking Into<String> is a great way to accept &str and String, but taking ToString or Display is an even better way as it now accepts &str, String and any type that can be converted into a string (which Into<String> implies but theres a special case for Strings here)

we've recently decided to use your library in twilight (a discord library) because it allows us to create query strings in a simpler way (twilight-rs/twilight#2348) and i think having this addition would make our (and of course many others') codebase much simpler, as we currently have to repeatedly call ToString::to_string, or Option::map(ToString::to_string) in the case of (with|push)_opt(_value)? ,when building the query parameters (like when passing bools as query param values for example)

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions