Info
This post is auto-generated from RSS feed The Rust Programming Language Forum - Latest topics. Source: Destructuring with haskell-style "as pattern"
Haskell has a nice feature where you can destructure a value and keep a reference to the whole value. So if f()
returns a tuple (a,b,c)
then q@(x,y,z) = f()
will store a
in x
etc and also q
will contain (a,b,c)
. This is sometimes a useful feature. Now, I don't think Rust has this feature, and I think I understand why, but I want to double check that I am getting this right.
So, Rust does not have this "as pattern" feature because destructuring moves the value, so you can't also keep a reference to the whole thing around, because it's been moved. Am I understanding that correctly?
8 posts - 6 participants
🏷️ rust_feed