Struct Store

Source
pub struct Store { /* private fields */ }
Expand description

A karmeliet triple store.

Implementations§

Source§

impl Store

Source

pub fn entity(&mut self) -> Entity

Create a new entity.

Source

pub fn insert<T: 'static>(&mut self, e: Entity, value: T) -> Option<T>

Attach an attribute of type T to the entity e.

If there already was an attribute of type T for that entity, the old value is returned, and the after_remove hook is run before inserting the new value.

Source

pub fn remove<T: 'static>(&mut self, e: Entity) -> Option<T>

Remove the attribute of type T from the entity e.

If no attribute of that type exists on that entity, None is returned.

Source

pub fn update<T: 'static, R>( &mut self, e: Entity, f: impl FnOnce(&mut T) -> R, ) -> Option<R>

Update the attribute of type T on the entity e with the given function.

If no attribute of that type exists on that entity, the function is not executed and None is returned.

If the attribute does exist, this will run both the after_remove and the before_insert hooks, with the previous and updated value respectively.

Source

pub fn upsert<T: Default + 'static, R>( &mut self, e: Entity, f: impl FnOnce(&mut T) -> R, ) -> R

Update the attribute of type T on the entity e with the given function.

If no attribute of that type exists on that entity, a defaut value is first inserted.

Like update, this will run both after_remove and before_insert hooks, unless the attribute didn’t exist yet, in which case only the before_insert hook is run.

Source

pub fn get<T: 'static>(&self, e: Entity) -> Option<&T>

Borrow the attribute of type T on the entity e.

If no attribute of that type exists on that entity, None is returned.

Source

pub fn contains<T: 'static>(&self, e: Entity) -> bool

Check whether the entity e has an attribute of type T.

Source

pub fn iter<T: 'static>(&self) -> AttrIter<'_, T>

Iterate over all entities with attribute of type T.

Source

pub fn hook_before_insert<T, H>(&mut self, hook: H)
where T: 'static, H: Fn(&mut Store, Entity, &T) + 'static,

Set a hook that will be run before an attribute of type T is inserted.

The hook will also run after an attribute is updated with update and upsert.

Source

pub fn hook_after_remove<T, H>(&mut self, hook: H)
where T: 'static, H: Fn(&mut Store, Entity, &T) + 'static,

Set a hook that will be run after an attribute of type T is removed.

The hook will also run before an attribute is updated with update and upsert.

Note that this hook is not run when the Store is dropped.

Trait Implementations§

Source§

impl Default for Store

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Drop for Store

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl Freeze for Store

§

impl !RefUnwindSafe for Store

§

impl !Send for Store

§

impl !Sync for Store

§

impl Unpin for Store

§

impl !UnwindSafe for Store

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.