Destructuring with haskell-style "as pattern"
⚓ Rust 📅 2025-06-03 👤 surdeus 👁️ 10Haskell 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