by mattmanser · 11y ago · 0 comments
https://github.com/tcr/rust-todomvc/blob/master/src/main.rs
Why put it all in the main? Why define functions as variables? Why .parent().unwrap().parent().unwrap()?
The parent navigation needs to be replaced by a jQuery-like .ancestors() macro.
This was an MVP so I wasn't focused on code quality over features; but I'm also learning Rust for the first time, so it came out less than impressive :)
> Why define functions as variables?
I'm not sure what you mean here, exactly. > Why .parent().unwrap().parent().unwrap()?
I'm not mega familiar with the code, but using a low-level binding to something else that has nulls often means a lot of Option, which means a lot of unwrapping. A nicer library could probably get rid of some of this. .unwrap()
In rust is generally a bad pattern to use. Its basically short hand for let o :Option< u64 >;
let value :u64 = match o {
Some( t ) => t,
None => panic!()
};
So if you don't met the condition, you explode. When ever you see .unwrap() in Rust just mentally switch it for /TODO add error handling */We almost changed 'unwrap' to 'assert', but people found it a bit too weird.
That is weird. idk I guess its already sort of being done, you're more or less asserting Option::Some( _ ) is the value.