[][src]Trait stowaway::Stowable

pub unsafe trait Stowable { }

Marker trait to indicate which types are safe to stow.

Currently, it is undefined behavior to read/write uninitialized memory in a primitive type, such as a pointer or usize, even if that memory is never "used". This means that types that have uninitialized bytes in their representation (such as structs with padding bytes) cannot be packed by stowaway, even if they would otherwise fit. It's not currently possible to detect if a struct might contain uninitialized bytes, so any types that want to be stowed must implement this trait.

This trait is implemented for most primitive and standard library types you might want to stow:

  • All integer & float types.
  • bool and char.
  • All primitive pointer types.
  • All arrays of Stowable (up to length 32, until const generics are stable)
  • All structured pointer types (Rc, Arc, etc)

Safety

Correct usage of this trait is critical to stowaway's safety guarantees. This struct can only be implemented on types that can never have uninitialized bytes anywhere in their representation (including padding bytes). Making this determination isn't trivial, though typically it's safe if sizeof(T) == sum(sizeof(fields in T)), and all of the fields in T are themselves Stowable.

Structs which are repr(transparent) are Stowable if their inner field is Stowable.

This trait can be safely derived for any struct with 0 or 1 field:

use stowaway::Stowable;
use std::sync::Arc;

#[derive(Debug, Clone, Stowable)]
struct ItemHandle<T> {
    ptr: Arc<T>
}
This example deliberately fails to compile
use stowaway::Stowable;

// This will not work; TwoFields has two fields
#[derive(Stowable)]
struct TwoFields {
    a: usize,
    b: usize,
}
This example deliberately fails to compile
use stowaway::Stowable;

// This will not work; the inner field isn't stowable
struct NotStowable {
    ptr: Arc<usize>,
}

#[derive(Stowable)]
struct Handle {
    ptr: NotStowable,
}

Implementations on Foreign Types

impl<T: ?Sized> Stowable for Box<T>[src]

impl<T: ?Sized> Stowable for Option<Box<T>>[src]

impl<T: ?Sized> Stowable for Rc<T>[src]

impl<T: ?Sized> Stowable for Option<Rc<T>>[src]

impl<T: ?Sized> Stowable for RcWeak<T>[src]

impl<T: ?Sized> Stowable for Option<RcWeak<T>>[src]

impl<T: ?Sized> Stowable for NonNull<T>[src]

impl<T: ?Sized> Stowable for Option<NonNull<T>>[src]

impl<T: ?Sized> Stowable for Arc<T>[src]

impl<T: ?Sized> Stowable for Option<Arc<T>>[src]

impl<T: ?Sized> Stowable for ArcWeak<T>[src]

impl<T: ?Sized> Stowable for Option<ArcWeak<T>>[src]

impl<T: ?Sized, '_> Stowable for Option<&'_ mut T>[src]

impl<T: ?Sized, '_> Stowable for Option<&'_ T>[src]

impl<T> Stowable for Vec<T>[src]

Loading content...

Implementors

impl Stowable for ()[src]

impl Stowable for bool[src]

impl Stowable for char[src]

impl Stowable for f32[src]

impl Stowable for f64[src]

impl Stowable for i8[src]

impl Stowable for i16[src]

impl Stowable for i32[src]

impl Stowable for i64[src]

impl Stowable for i128[src]

impl Stowable for isize[src]

impl Stowable for u8[src]

impl Stowable for u16[src]

impl Stowable for u32[src]

impl Stowable for u64[src]

impl Stowable for u128[src]

impl Stowable for usize[src]

impl<T: Stowable> Stowable for Stowaway<T>[src]

impl<T: Stowable> Stowable for [T; 0][src]

impl<T: Stowable> Stowable for [T; 1][src]

impl<T: Stowable> Stowable for [T; 2][src]

impl<T: Stowable> Stowable for [T; 3][src]

impl<T: Stowable> Stowable for [T; 4][src]

impl<T: Stowable> Stowable for [T; 5][src]

impl<T: Stowable> Stowable for [T; 6][src]

impl<T: Stowable> Stowable for [T; 7][src]

impl<T: Stowable> Stowable for [T; 8][src]

impl<T: Stowable> Stowable for [T; 9][src]

impl<T: Stowable> Stowable for [T; 10][src]

impl<T: Stowable> Stowable for [T; 11][src]

impl<T: Stowable> Stowable for [T; 12][src]

impl<T: Stowable> Stowable for [T; 13][src]

impl<T: Stowable> Stowable for [T; 14][src]

impl<T: Stowable> Stowable for [T; 15][src]

impl<T: Stowable> Stowable for [T; 16][src]

impl<T: Stowable> Stowable for [T; 17][src]

impl<T: Stowable> Stowable for [T; 18][src]

impl<T: Stowable> Stowable for [T; 19][src]

impl<T: Stowable> Stowable for [T; 20][src]

impl<T: Stowable> Stowable for [T; 21][src]

impl<T: Stowable> Stowable for [T; 22][src]

impl<T: Stowable> Stowable for [T; 23][src]

impl<T: Stowable> Stowable for [T; 24][src]

impl<T: Stowable> Stowable for [T; 25][src]

impl<T: Stowable> Stowable for [T; 26][src]

impl<T: Stowable> Stowable for [T; 27][src]

impl<T: Stowable> Stowable for [T; 28][src]

impl<T: Stowable> Stowable for [T; 29][src]

impl<T: Stowable> Stowable for [T; 30][src]

impl<T: Stowable> Stowable for [T; 31][src]

impl<T: Stowable> Stowable for [T; 32][src]

impl<T: ?Sized> Stowable for *const T[src]

impl<T: ?Sized> Stowable for *mut T[src]

impl<T: ?Sized, '_> Stowable for &'_ T[src]

impl<T: ?Sized, '_> Stowable for &'_ mut T[src]

Loading content...