5 ms·
I strongly agree with this. Rust has been a pleasure to learn, and I've been using it for everything from small scripts to even some minor web-dev. That said I
by chias 10y ago
I strongly agree with this. Rust has been a pleasure to learn, and I've been using it for everything from small scripts to even some minor web-dev. That said I do think there are areas in which using Rust is legitimately not a great idea. For example, I needed to convert a URL path into a filesystem path, and my code looks like this:
let mut basepath = PathBuf::from(path_arg);
for component in req.url.path() {
basepath.push(percent_decode(component.as_bytes()).decode_utf8_lossy().into_owned());
}
Granted -- each part of that makes a lot of sense, and I think it would be to Rust's detriment for things not to be that way. But when my focus has to be on rapid development rather than exacting precision, this sort of verbosity can get in the way.
Personally, I have been using Rust anyway because I am trying to shift my development habits away from rapid development and towards exacting precision, and to this end Rust has been a godsend. But I can easily understand why this verbosity may push someone away. I do note, however, that verbosity is not the GP's complaint here.
- tatterdemalion 10y agoIt 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.