Trait Packed

Source
pub trait Packed {
    // Provided method
    unsafe fn repr_c_optimization_safe(_version: u32) -> IsPacked { ... }
}
Expand description

This trait describes whether a type is such that it can just be blitted. See method repr_c_optimization_safe. Note! The name Packed is a little misleading. A better name would be ‘packed’

Provided Methods§

Source

unsafe fn repr_c_optimization_safe(_version: u32) -> IsPacked

This method returns true if the optimization is allowed for the protocol version given as an argument. This may return true if and only if the given protocol version has a serialized format identical to the memory layout of the given protocol version. Note, the only memory layout existing is that of the most recent version, so Packed-optimization only works when disk-format is identical to memory version.

This can return true for types which have an in-memory layout that is packed and therefore identical to the layout that savefile will use on disk. This means that types for which this trait is implemented can be serialized very quickly by just writing their raw bits to disc.

Rules to allow returning true:

  • The type must “be Copy” (i.e, implement the Copy-trait)
  • The type must not contain any padding (if there is padding, backward compatibility will fail, since in fallback mode regular savefile-deserialize will be used, and it will not use padding)
  • The type must have a strictly deterministic memory layout (no field order randomization). This typically means repr(C)
  • All the constituent types of the type must also implement Packed (correctly).

Constructing an instance of ‘IsPacked’ with value ‘true’ is not safe. See documentation of ‘IsPacked’. The idea is that the Packed-trait itself can still be safe to implement, it just won’t be possible to get hold of an instance of IsPacked(true). That is, a safe implementation of Packed can’t return IsPacked(true), if everything else follows safety rules. To make it impossible to just ‘steal’ such a value from some other thing implementing ‘Packed’, this method is marked unsafe (however, it can be left unimplemented, making it still possible to safely implement Packed).

§Safety

The returned value must not be used, except by the Savefile-framework. It must not be forwarded anywhere else.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl Packed for bool

Source§

impl Packed for char

Source§

impl Packed for f32

Source§

impl Packed for f64

Source§

impl Packed for i8

Source§

impl Packed for i16

Source§

impl Packed for i32

Source§

impl Packed for i64

Source§

impl Packed for i128

Source§

impl Packed for isize

Source§

impl Packed for str

Source§

impl Packed for u8

Source§

impl Packed for u16

Source§

impl Packed for u32

Source§

impl Packed for u64

Source§

impl Packed for u128

Source§

impl Packed for ()

Source§

impl Packed for usize

Source§

impl Packed for String

Source§

impl Packed for Arc<str>

Source§

impl Packed for AtomicBool

Source§

impl Packed for AtomicI8

Source§

impl Packed for AtomicI16

Source§

impl Packed for AtomicI32

Source§

impl Packed for AtomicI64

Source§

impl Packed for AtomicIsize

Source§

impl Packed for AtomicU8

Source§

impl Packed for AtomicU16

Source§

impl Packed for AtomicU32

Source§

impl Packed for AtomicU64

Source§

impl Packed for AtomicUsize

Source§

impl Packed for Duration

Source§

impl Packed for Error

Source§

impl Packed for PathBuf

Source§

impl Packed for SystemTime

Source§

impl Packed for BitSet<u32>

Source§

impl Packed for BitSet<u32>

Source§

impl Packed for BitVec<u32>

Source§

impl Packed for BitVec<u32>

Source§

impl<'a, T: 'a + ToOwned + ?Sized> Packed for Cow<'a, T>

Source§

impl<K> Packed for BTreeSet<K>

Source§

impl<K, S: BuildHasher> Packed for HashSet<K, S>

Source§

impl<K, V> Packed for BTreeMap<K, V>

Source§

impl<K: Eq + Hash, S: BuildHasher> Packed for IndexSet<K, S>

Source§

impl<K: Eq + Hash, V, S: BuildHasher> Packed for HashMap<K, V, S>

Source§

impl<K: Eq + Hash, V, S: BuildHasher> Packed for IndexMap<K, V, S>

Source§

impl<T1> Packed for Range<T1>

Source§

impl<T1: Packed> Packed for (T1,)

Source§

impl<T1: Packed, T2: Packed> Packed for (T1, T2)

Source§

impl<T1: Packed, T2: Packed, T3: Packed> Packed for (T1, T2, T3)

Source§

impl<T1: Packed, T2: Packed, T3: Packed, T4: Packed> Packed for (T1, T2, T3, T4)

Source§

impl<T> Packed for Option<T>

Source§

impl<T> Packed for Box<T>

Source§

impl<T> Packed for BinaryHeap<T>

Source§

impl<T> Packed for VecDeque<T>

Source§

impl<T> Packed for Rc<T>

Source§

impl<T> Packed for Arc<T>

Source§

impl<T> Packed for Vec<T>

Source§

impl<T> Packed for RefCell<T>

Source§

impl<T> Packed for PhantomData<T>

Source§

impl<T> Packed for Mutex<T>

Source§

impl<T> Packed for Mutex<T>

Source§

impl<T> Packed for RwLock<T>

Source§

impl<T, R> Packed for Result<T, R>

Source§

impl<T: Array> Packed for SmallVec<T>

Source§

impl<T: Packed> Packed for Box<[T]>

Source§

impl<T: Packed> Packed for Arc<[T]>

Source§

impl<T: Packed> Packed for Cell<T>

Source§

impl<T: Packed, const N: usize> Packed for [T; N]

Source§

impl<V: Packed, const C: usize> Packed for ArrayVec<V, C>

Source§

impl<const C: usize> Packed for ArrayString<C>

Implementors§