External Publication
Visit Post

Semantic of smart pointers

Rust Internals [Unofficial] May 19, 2026
Source

Thank you for your reply!

robofinch:

If it’s for the soundness of unsafe code, then I think that needs are commonly fairly specific to the unsafe code.

Yes, I care about unsafe code.

robofinch:

it doesn’t seem entirely unreasonable that a non-std Cow-like type could be copy-on-write while implementing both AsRef and AsMut. I don’t think that would be a good idea

Yes, and that is exactly why I thought defining a smart pointer is hard. Rc, for another example, cannot implement AsMut.

robofinch:

While I’ve been assuming that there’s some reason you can’t just use &mut [u8]

Yes, &mut [u8] can work.

robofinch:

it’d be even better if your code didn’t need to own the buffer.

Then if the struct containing the reference needs to be moved around, it will be very hard for the library user to maintain the code, I guess.

Discussion in the ATmosphere

Loading comments...