4 ms·
> using generics for things like RC, ARC There is an unstable feature for "box syntax" which both allows you to construct a `Box<T>` as let foo = box a (instea
by thinkharderdev 3y ago
> using generics for things like RC, ARC
There is an unstable feature for "box syntax" which both allows you to construct a `Box<T>` as let foo = box a (instead of let foo = Box::new(a)) but also to use box as a keyword in pattern matches to deref the box automatically. So
struct Foo {
value: Box<Bar>
};
let Foo { value: box Bar } (in which case value is bound to a &Bar) which was really nice.
It got subsumed into a more generic "deref patterns" project which doesn't seem to be going anywhere but I hope it does because it makes the language much more ergonomic IMO.
- SkiFire13 3y agoThe `box` syntax to create `Box`es has been removed because it was broken. The initial idea was to have it initialize the value directly in the heap, but that never worked for function calls. The `box` pattern instead remained as it was still useful to have (really unfortunate for the perma-unstable status though).
- thinkharderdev 3y agoAh didn't realized it had been removed. I gave up on it after it became clear it was never going to make it into stable rust. I do hope deref patterns gets some traction though as it could really be a nice feature.