Trait StableAsRef

Source
pub unsafe trait StableAsRef { }
Expand description

Marker trait that indicates that a type is guaranteed safe to use as backing storage for String.

In order to be safe, a storage type T needs to guarantee the following:

  • If T implements AsRef<[u8]> and/or AsMut<[u8]>, the contents of T as visible the byte slice returned by as_ref and as_mut may only be mutated through mutable references or owned access. In other words, no use of interior mutability.

  • If T implements AsRef<[u8]>, the as_ref method must always return the same slice of bytes (unless the storage is mutated).

  • If T implements AsRef<[u8]> and AsMut<[u8]>, the as_mut method must return a mutable reference to the same slice of bytes as the as_ref method returns.

  • If T implements AsRef<[u8]> and Default, the default value must represent the empty byte sequence. In other words, T::default().as_ref().len() == 0.

  • If T implements AsRef<[u8]> and From<&[u8]>, it must do so in such a way that the byte slice returned by as_ref is equal to the byte slice provided to the from method.

Implementations on Foreign Types§

Source§

impl StableAsRef for str

Source§

impl StableAsRef for String

Source§

impl StableAsRef for Vec<u8>

Source§

impl StableAsRef for Bytes

Source§

impl StableAsRef for BytesMut

Source§

impl StableAsRef for [u8; 0]

Source§

impl StableAsRef for [u8; 1]

Source§

impl StableAsRef for [u8; 2]

Source§

impl StableAsRef for [u8; 3]

Source§

impl StableAsRef for [u8; 4]

Source§

impl StableAsRef for [u8; 5]

Source§

impl StableAsRef for [u8; 6]

Source§

impl StableAsRef for [u8; 7]

Source§

impl StableAsRef for [u8; 8]

Source§

impl StableAsRef for [u8; 9]

Source§

impl StableAsRef for [u8; 10]

Source§

impl StableAsRef for [u8; 11]

Source§

impl StableAsRef for [u8; 12]

Source§

impl StableAsRef for [u8; 13]

Source§

impl StableAsRef for [u8; 14]

Source§

impl StableAsRef for [u8; 15]

Source§

impl StableAsRef for [u8; 16]

Source§

impl StableAsRef for [u8]

Source§

impl<'a, T> StableAsRef for &'a T
where T: StableAsRef,

Source§

impl<'a, T> StableAsRef for &'a mut T
where T: StableAsRef,

Source§

impl<T> StableAsRef for Box<T>
where T: StableAsRef,

Source§

impl<T> StableAsRef for Rc<T>
where T: StableAsRef,

Source§

impl<T> StableAsRef for Arc<T>
where T: StableAsRef,

Implementors§