0

Add MaybeUninit::(slice_)as_bytes(_mut) by Amanieu · Pull Request #89747 · rust-...

 2 years ago
source link: https://github.com/rust-lang/rust/pull/89747
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

This comment has been hidden.

This seems related to some of the questions that have come up in the safe transmute work.

For the mut versions, this allows writing arbitrary data to a value or slice. That data still won't become usable until a call to assume_init, which is unsafe, so this isn't unsound, but as far as I know, doing something like that would previously have required mem::transmute.

In either case, this would make it very easy to rely on the internal layout of a type, which a crate may not have intended to make public. So at the very least, I think we need a comment noting that the ability to access the bytes of private fields or the exact layout of a structure does not necessarily make those details part of a crate's stable ABI.

I don't have any objections to these methods existing; I just want to make sure we note (and where appropriate document) what new capabilities these methods expose, and the potential hazards associated with them.


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK