Trait stam::Storable

source ·
pub trait Storable: PartialEq + TypeInfo + Sealedwhere
    Self: Sized,{
    type HandleType: Handle;
    type StoreType: StoreFor<Self>;

    // Required method
    fn carries_id() -> bool;

    // Provided methods
    fn handle(&self) -> Option<Self::HandleType> { ... }
    fn handle_or_err(&self) -> Result<Self::HandleType, StamError> { ... }
    fn id(&self) -> Option<&str> { ... }
    fn id_or_err(&self) -> Result<&str, StamError> { ... }
    fn with_id(self, id: String) -> Self
       where Self: Sized { ... }
    fn wrap_in<'store>(
        &'store self,
        store: &'store Self::StoreType
    ) -> Result<WrappedItem<'store, Self>, StamError>
       where Self: Sized { ... }
    fn wrap_owned_in<'store>(
        self,
        store: &'store Self::StoreType
    ) -> Result<WrappedItem<'store, Self>, StamError>
       where Self: Sized { ... }
    fn set_handle(&mut self, handle: <Self as Storable>::HandleType) { ... }
    fn bound(&mut self) { ... }
    fn generate_id(self, idmap: Option<&mut IdMap<Self::HandleType>>) -> Self
       where Self: Sized { ... }
}

Required Associated Types§

Required Methods§

source

fn carries_id() -> bool

Does this type support an ID?

Provided Methods§

source

fn handle(&self) -> Option<Self::HandleType>

Retrieve the internal (numeric) id. For any type T uses in StoreFor<T>, this may be None only in the initial stage when it is still unbounded to a store.

source

fn handle_or_err(&self) -> Result<Self::HandleType, StamError>

Like Self::handle() but returns a StamError::Unbound error if there is no internal id.

source

fn id(&self) -> Option<&str>

Get the public ID

source

fn id_or_err(&self) -> Result<&str, StamError>

Like Self::id() but returns a StamError::NoIdError error if there is no internal id.

source

fn with_id(self, id: String) -> Selfwhere Self: Sized,

Builder pattern to set the public Id

source

fn wrap_in<'store>( &'store self, store: &'store Self::StoreType ) -> Result<WrappedItem<'store, Self>, StamError>where Self: Sized,

Returns a wrapped reference to this item and the store that owns it. This allows for some more introspection on the part of the item. reverse of StoreFor<T>::wrap()

source

fn wrap_owned_in<'store>( self, store: &'store Self::StoreType ) -> Result<WrappedItem<'store, Self>, StamError>where Self: Sized,

Returns a wrapped reference to this item and the store that owns it. This allows for some more introspection on the part of the item. reverse of StoreFor<T>::wrap_owned()

source

fn set_handle(&mut self, handle: <Self as Storable>::HandleType)

Set the internal ID. May only be called once (though currently not enforced).

source

fn bound(&mut self)

Callback function that is called after an item is bound to a store

source

fn generate_id(self, idmap: Option<&mut IdMap<Self::HandleType>>) -> Selfwhere Self: Sized,

Generate a random ID in a given idmap (adds it to the map and assigns it to the item)

Implementors§