You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
/// This trait is meant to map equivalences between raw structs and their
/// corresponding rust values.
pub trait Repr<T> {
/// This function "unwraps" a rust value (without consuming it) into its raw
/// struct representation. This can be used to read/write different values
/// for the struct. This is a safe method because by default it does not
/// enable write-access to the fields of the return value in safe code.
#[inline]
fn repr(&self) -> T { unsafe { mem::transmute_copy(&self) } }
}
Implementing is done like so:
impl<T> Repr<Slice<T>> for [T] {}
A safe implementation invokes a transmute between arbitrary types. Perhaps Repr is more appropriately an unsafe trait?
The text was updated successfully, but these errors were encountered:
The default implementation of .repr() will call conveniently call
transmute_copy which should be appropriate for all implementors, but is
memory unsafe if used wrong.
Fixesrust-lang#22260
You need to use `unsafe impl` to implement the Repr trait now.
[breaking-change]
Here's the definition
Implementing is done like so:
A safe implementation invokes a transmute between arbitrary types. Perhaps
Repr
is more appropriately an unsafe trait?The text was updated successfully, but these errors were encountered: