Struct stepflow::object::ObjectStore [−][src]
A store for objects that are weak referenced by an ID and optional name.
There are two different ways to insert an object.
- Use
insert_new
which takes a closure that receives the ID for the new object - Get an ID with
reserve_id
and thenregister
the object with that ID
To add objects with an associated name, use the corresponding
insert_new_named
and register_named
instead.
Examples
// create an ObjectStore with a test object let mut store = ObjectStore::new(); let object_id = store.insert_new_named("test object", |id| Ok(Object { id })).unwrap(); // get the object either by ID or name let object = store.get(&object_id).unwrap(); let object = store.get_by_name("test object").unwrap();
Implementations
impl<'s, T, TID> ObjectStore<T, TID> where
T: ObjectStoreContent<IdType = TID> + ObjectStoreContent,
TID: Eq + Hash + Clone,
[src]
T: ObjectStoreContent<IdType = TID> + ObjectStoreContent,
TID: Eq + Hash + Clone,
pub fn new() -> ObjectStore<T, TID>
[src]
Create a new ObjectStore
pub fn with_capacity(capacity: usize) -> ObjectStore<T, TID>
[src]
Create a new ObjectStore with initial capacity
pub fn reserve_id(&mut self) -> TID
[src]
Reserve an ID in the ObjectStore. Generally followed with a call to register
using the ID.
pub fn register(&mut self, object: T) -> Result<TID, IdError<TID>>
[src]
Registers an object into the ObjectStore
pub fn register_named<STR>(
&mut self,
name: STR,
object: T
) -> Result<TID, IdError<TID>> where
STR: Into<Cow<'static, str>>,
[src]
&mut self,
name: STR,
object: T
) -> Result<TID, IdError<TID>> where
STR: Into<Cow<'static, str>>,
Registers a named object into the ObjectStore
pub fn insert_new<CB>(&mut self, cb: CB) -> Result<TID, IdError<TID>> where
CB: FnOnce(TID) -> Result<T, IdError<TID>>,
[src]
CB: FnOnce(TID) -> Result<T, IdError<TID>>,
Reserves an ID and registers the object in a single call. The object created must use the ID given to the closure.
pub fn insert_new_named<CB, STR>(
&mut self,
name: STR,
cb: CB
) -> Result<TID, IdError<TID>> where
STR: Into<Cow<'static, str>>,
CB: FnOnce(TID) -> Result<T, IdError<TID>>,
[src]
&mut self,
name: STR,
cb: CB
) -> Result<TID, IdError<TID>> where
STR: Into<Cow<'static, str>>,
CB: FnOnce(TID) -> Result<T, IdError<TID>>,
Reserves an ID and registers the named object in a single call. The object created must use the ID given to the closure.
pub fn id_from_name(&self, name: &str) -> Option<&TID>
[src]
Get the Object ID from the name
pub fn name_from_id(&self, id: &TID) -> Option<&str>
[src]
Get the name from the Object ID
pub fn get_by_name(&self, name: &str) -> Option<&T>
[src]
Get an object by its name
pub fn get(&self, id: &TID) -> Option<&T>
[src]
Get an object by its ID
pub fn get_mut(&mut self, id: &TID) -> Option<&mut T>
[src]
Get a mutable reference to the object
pub fn iter_names(&self) -> impl Iterator<Item = (&Cow<'static, str>, &TID)>
[src]
Trait Implementations
Auto Trait Implementations
impl<T, TID> RefUnwindSafe for ObjectStore<T, TID> where
T: RefUnwindSafe,
TID: RefUnwindSafe,
[src]
T: RefUnwindSafe,
TID: RefUnwindSafe,
impl<T, TID> Send for ObjectStore<T, TID> where
T: Send,
TID: Send,
[src]
T: Send,
TID: Send,
impl<T, TID> Sync for ObjectStore<T, TID> where
T: Sync,
TID: Sync,
[src]
T: Sync,
TID: Sync,
impl<T, TID> Unpin for ObjectStore<T, TID> where
T: Unpin,
TID: Unpin,
[src]
T: Unpin,
TID: Unpin,
impl<T, TID> UnwindSafe for ObjectStore<T, TID> where
T: UnwindSafe,
TID: UnwindSafe,
[src]
T: UnwindSafe,
TID: UnwindSafe,
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> AsAny for T where
T: Any,
[src]
T: Any,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T> Instrument for T
[src]
pub fn instrument(self, span: Span) -> Instrumented<Self>
[src]
pub fn in_current_span(self) -> Instrumented<Self>
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,