3 ms·
First, Box lacks some ergonomics, it's a pain dealing with when matching Now, as for the article, I don't really follow their argument. Box<T> owns its content
by __s 2y ago
First, Box lacks some ergonomics, it's a pain dealing with when matching
Now, as for the article, I don't really follow their argument. Box<T> owns its contents. Hence why it drops its contents afterwards, unlike &T. If someone needs this aliasable box type, they should define a different DropPtr. "It's just a pointer" can also be said of `&T` & `&mut T` (where T: Sized)
- remram 2y ago> It's just a pointer" can also be said of `&T` & `&mut T But that's the point: you can assign your &T to a pointer and know that it won't be invalidated by merely moving the &T. That is not true for Box<T>.
- eddd-ddde 2y agoExcept is not the same thing? You can copy a reference, you can't copy a box (without having the T be copy as well). A box is a pointer AND the storage at the same time. To move it means to move the storage as well, unlike a regular reference.
- remram 2y ago> A box is a pointer AND the storage at the same time. That's just the way you decide to see it. Most people don't, in fact the actual documentation is quite different: >> A pointer type that uniquely owns a heap allocation of type T. This explicitly describes it as a pointer, pointing to a single allocation. https://doc.rust-lang.org/nightly/std/boxed/struct.Box.html https://doc.rust-lang.org/nightly/std/boxed/struct.Box.html
- spoiler 2y ago> First, Box lacks some ergonomics, it's a pain dealing with when matching Agreed, but this should become better once box_patterns is stable https://doc.rust-lang.org/beta/unstable-book/language-features/box-patterns.html https://doc.rust-lang.org/beta/unstable-book/language-featur...
- estebank 2y agoThat feature is almost assuredly not going to land on stable but the more general "deref_patterns" which would allow matching on boxed values, as well as on `Vec`s and `String`s will. It is not anywhere close to finished, but I am convinced it will land.
- airstrike 2y agoLinks with more info on the current state of deref patterns https://github.com/rust-lang/rust/issues/87121 https://github.com/rust-lang/rust/issues/87121 https://hackmd.io/4qDDMcvyQ-GDB089IPcHGg https://hackmd.io/4qDDMcvyQ-GDB089IPcHGg
- spoiler 2y agoOh I missed that one. Thanks for pointing it out! Here's the proposal for anyone else who's curious https://hackmd.io/4qDDMcvyQ-GDB089IPcHGg https://hackmd.io/4qDDMcvyQ-GDB089IPcHGg