4 ms·
I appreciate it's to demo the capacity to compile Rust to js, but that's some really nasty code. https://github.com/tcr/rust-todomvc/blob/master/src/main.rs ht
by mattmanser 11y ago
I appreciate it's to demo the capacity to compile Rust to js, but that's some really nasty code.
https://github.com/tcr/rust-todomvc/blob/master/src/main.rs 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()?
- seivan 11y agoI wonder if it would looks a bit nicer with .jsx support.
- timcameronryan 11y agoI can't wait for a JSX crate on Cargo.
- steveklabnik 11y ago> 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.
- valarauca1 11y ago>which means a lot of unwrapping .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 */
- steveklabnik 11y agoYeah, I was just using "unwrapping" as a more general term for "extract the T out." We almost changed 'unwrap' to 'assert', but people found it a bit too weird.
- valarauca1 11y ago>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.
- timcameronryan 11y agoIt is nasty code! I started refactoring before I hit some struct-alignment bugs (fixed on later Rust versions): https://github.com/tcr/rust-todomvc/blob/tcr-wip/src/main.rs https://github.com/tcr/rust-todomvc/blob/tcr-wip/src/main.rs 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 :)