Even regardless of performance, it would be quite nice to have! I've been meaning[1] to build a small prototype to do something clever[2] with it, but didn't have the time yet. Feel free to steal these ideas :)
[1]: https://scribbles.pascalhertleif.de/impl-virtual-dom-cli-lib... [2]: https://scribbles.pascalhertleif.de/rich-diffs-of-rendered-h...
let id = node.parent().unwrap()
.parent().unwrap()
.data_get("id").unwrap()
.parse::<usize>().unwrap();
If there is something horrible about that I don't see it.Dealing with this case properly without using a single `?`, gets really ugly with a lot of nested
if let Some(parent) = node.parent() {This could be a function to isolate just the attribute you need, but seeing the example as it is presented can be off-putting from people used to scripting languages like ruby/python, which are more concise.
? is far easier and faster to type than .unwrap().
So no, there's nothing horrible that I see, there is something horrible that I feel though.
Isn't unwrap():
a) boilerplate
b) repetitive?
In other words, it's boilerplate here because this particular operation has many possible failure modes, and Rust is pointing those out to you.
It's repetitive in this particular instance, but doesn't have to be in general.
if the node always having a parent is a invariant of your application, you should use `expect` with a clear error message when the invariant is broken.
if your node can have no parents then you want to handle this case explicitly with a `if let Some(parent) = node.parent() {` pattern.
Most of the cost of vdom is the resulting DOM ops and reflow/restyle the browser needs to do. It may be faster than the fastest today, but you're unlikely to see any kind of performance leap or even anything noticeable.
I see that there is some discussion here [1], including a suggestion to add a Haskell-style "do" block. But that's just one guy's blog post.
It sounds like there are some that would like to move Rust in the direction of becoming more Haskell/ML-like (which is to say more purely functional) rather than the current balance between imperative and functional? Is there any internal tension in that regard?
This leads to a situation where, if there were to be a monad trait, that trait should abstract over not only types, but another traits generically.
Not to speak about some other hurdles, like lifetimes. The design space is inherently more convoluted than in languages with boxed, possibly dynamically dispatched types. It may be possible, but it's not easy, and we can't copy the monads straightforwardly from Haskell or Scala.
Because people wouldn't expect it to return due to behaviour of existing languages yet that's what it does in Rust?
Many are in favor of doing it, though. I'm personally against it.