this post was submitted on 17 Nov 2023
17 points (94.7% liked)
Rust
6029 readers
2 users here now
Welcome to the Rust community! This is a place to discuss about the Rust programming language.
Wormhole
Credits
- The icon is a modified version of the official rust logo (changing the colors to a gradient and black background)
founded 1 year ago
MODERATORS
you are viewing a single comment's thread
view the rest of the comments
view the rest of the comments
My quick notes which are tailored to beginners:
Use
Option::ok_or_else()
andResult::map_err()
instead oflet .. else
.let .. else
didn't always exist. And you might find that some old timers are slightly triggered by it.Option
s as iterators (yesOption
s are iterators).?
operator and theTry
traitType inference and generic params
(Borken sanitization will probably butcher this code, good thing the problem will be gone in Lemmy 0.19)
Three tips here:
headers
will be returned as a struct field, the type of which is already known.collect()
itself. That may prove useful in other scenarios.Result
/Option
if the iterator items areResult
s/Option
s. So that.unwrap()
is not an ergonomic necessity ๐Minor point
.into()
or.to_owned()
for&str => String
conversions.make good use of the crate echo system
http
crate is the compatibility layer used HTTP rust implementations. Check it out and maybe incorporate it into your experimental/educational code.Alright, I will stop myself here.
Thanks! Really good points here, will have to find some time to apply them.