|
|
|
|
|
by mrheosuper
263 days ago
|
|
I have no specific compaints, but here one example i saw online, and i'm talking from a C dev perspective. let x: Option<Result<Vec<i32>, std::num::ParseIntError>> = Some(Ok(vec![1, 2, 3]));
let flattened = x
.map(|r| r.unwrap_or_default())
.unwrap_or_else(|| Vec::<i32>::new());
I have no idea what the code is doing here, but while reading python or JS code, i can make an educated guess what it's doing.I have no experience with Rust so it makes sense i dont understand, but i also have no experience with Python or JS. |
|
Also this code isn't a thing you'd actually do, it's maybe an illustration or part of an example I suppose
You see that vec![1, 2, 3] ? That's what we're getting at the end, a growable array with three integers in it. All the other stuff is machinery to handle errors which in fact have not happened.
Is the same effect, although probably for style you'd write: