3 ms·
An example: So suppose you have the following pseudo code: x = f() In other languages you start using 'x' straight away. You can call member functions on
by sudeepj 8y ago
An example:
So suppose you have the following pseudo code:
x = f()
In other languages you start using 'x' straight away. You can call member functions on it, compare it, etc.
In Rust if x happens to be of type Option or Result (which are wrapper types i.e. they wrap the value), then you need to understand these first very well to write idiomatic Rust code. These types have combinator functions like 'map', 'and', 'and_then', 'or', 'or_else', 'unwrap_else', etc. if unwrap() is not suitable for your use case. If you are coming from a non-functional language, one cannot help get a feeling that all you wanted was to use the value and you have to learn so much upfront. At the end of it you are mentally exhausted.
My productivity increased a lot, once I realized that there is a pattern to these and knowledge gain with Option & Result is transferrable to using Future's combinators as well. It is very hard to explain it to someone as to how to get to this state. There lies the challenge with teaching Rust and I think Steve Klabnik and team has done really good job with documentation.
- steveklabnik 8y agoThank you!