3 ms·
It seems like you're using the url crate but a different version from what I have docs for (the path() method I see doesn't return an iterator). But I believe t
by tatterdemalion 10y ago
It seems like you're using the url crate but a different version from what I have docs for (the path() method I see doesn't return an iterator). But I believe that some of those conversions are not optimally necessary.
Definitely the into_owned is unnecessary and could be replaced by an & before `percent_decode`. This ownership wrangling is something we'd like to address in the coming year.
Then I'm not sure about percent_decode. I think there could be a better convenience for that back and forth casting between utf8 and bytes that's going on.
The only real decision you're making here is decode_utf8_lossy vs decode_utf8. I'd like to think this could be encapsulated as two methods on the Url type.
- chias 10y agoThanks for the critique! This is actually super helpful to me as I try to grow as a Rust developer. The point I'm trying to make though, is that if the developer's focus is on rapid development (which I imagine most people in webdev are), then at the end of the day I just want to urldecode something, and not necessarily worry about the character encodings etc.
- tatterdemalion 10y agoThat wasn't meant as a critique per se, the only thing that's your mistake (rather than a paucity of APIs) is the into_owned bit, and we want to deal at the language/std level with a lot of the common cases where type errors misdirect you into "into_owned"ing things.