pub trait Store<O>: EventSource<StoreUpdate> {
    type ByType<'a, T>: Iterator<Item = (u32, &'a T)> + 'a
       where O: 'a,
             T: MonoObject + 'a,
             Self: 'a;
    type IdsByType<'a, T>: Iterator<Item = u32> + 'a
       where O: 'a,
             T: 'static,
             Self: 'a;

Show 15 methods // Required methods fn insert<T: Into<O> + 'static>( &mut self, id: u32, object: T ) -> Result<&mut T, T>; fn insert_with_state<T: Into<O> + MonoObject + 'static>( &mut self, id: u32, object: T ) -> Result<(&mut T, &mut T::SingletonState), T>; fn allocate<T: Into<O> + 'static>( &mut self, object: T ) -> Result<(u32, &mut T), T>; fn remove(&mut self, id: u32) -> Option<O>; fn get_state<T: MonoObject>(&self) -> Option<&T::SingletonState>; fn get_state_mut<T: MonoObject>(&mut self) -> Option<&mut T::SingletonState>; fn get_with_state<T: MonoObject>( &self, id: u32 ) -> Result<(&T, &T::SingletonState), GetError>; fn get_with_state_mut<T: MonoObject>( &mut self, id: u32 ) -> Result<(&mut T, &mut T::SingletonState), GetError>; fn get<T: 'static>(&self, id: u32) -> Result<&T, GetError>; fn get_mut<T: 'static>(&mut self, id: u32) -> Result<&mut T, GetError>; fn contains(&self, id: u32) -> bool; fn try_insert_with( &mut self, id: u32, f: impl FnOnce() -> O ) -> Option<&mut O>; fn try_insert_with_state<T: Into<O> + MonoObject + 'static>( &mut self, id: u32, f: impl FnOnce(&mut T::SingletonState) -> T ) -> Option<(&mut T, &mut T::SingletonState)>; fn by_type<T: MonoObject + 'static>(&self) -> Self::ByType<'_, T>; fn ids_by_type<T: 'static>(&self) -> Self::IdsByType<'_, T>;
}
Expand description

Object store

For storing bound objects for a client.

Besides storing objects, the object store also needs to store states associated with types of objects. These are states that are shared by all objects of a certain type. For example, there could be a single instance of “SurfaceObjectState”, that is shared and used by all “Surface” objects in the object store. States are created when the first object of a certain type is inserted into the store, and destroyed when the last object of that type is removed from the store. See MonoObject::SingletonState for more information.

The store is also an event source, and will emit events when objects are inserted or removed from the store.

Required Associated Types§

source

type ByType<'a, T>: Iterator<Item = (u32, &'a T)> + 'a where O: 'a, T: MonoObject + 'a, Self: 'a

Type of iterator returned by by_type

source

type IdsByType<'a, T>: Iterator<Item = u32> + 'a where O: 'a, T: 'static, Self: 'a

Type of iterator returned by ids_by_type_mut

Required Methods§

source

fn insert<T: Into<O> + 'static>( &mut self, id: u32, object: T ) -> Result<&mut T, T>

Insert object into the store with the given ID. Returns a unique reference to the inserted object if successful, Err(T) if the ID is already in use.

This is for when the client wants to allocate an object with the given ID. According to the wayland spec, the ID must be less than 0xff000000

source

fn insert_with_state<T: Into<O> + MonoObject + 'static>( &mut self, id: u32, object: T ) -> Result<(&mut T, &mut T::SingletonState), T>

Insert object into the store with the given ID. Returns a unique reference to the inserted object and its singleton state if successful, Err(T) if the ID is already in use.

source

fn allocate<T: Into<O> + 'static>( &mut self, object: T ) -> Result<(u32, &mut T), T>

Allocate a new ID for the client, associate object for it. This is for inserting server allocated objects. According to the wayland spec, the ID must start from 0xff000000

source

fn remove(&mut self, id: u32) -> Option<O>

Remove an object from the store. Returns the removed object if it is found.

source

fn get_state<T: MonoObject>(&self) -> Option<&T::SingletonState>

Returns the singleton state associated with an object type. Returns None if no object of that type is in the store, or if the object type does not have a singleton state.

Panics

Panics if AnyObject::type_id or AnyObject::new_singleton_state is not properly implemented for O.

source

fn get_state_mut<T: MonoObject>(&mut self) -> Option<&mut T::SingletonState>

source

fn get_with_state<T: MonoObject>( &self, id: u32 ) -> Result<(&T, &T::SingletonState), GetError>

Get a reference an object with its associated singleton state

Panics

Panics if AnyObject::type_id or AnyObject::new_singleton_state is not properly implemented for O.

source

fn get_with_state_mut<T: MonoObject>( &mut self, id: u32 ) -> Result<(&mut T, &mut T::SingletonState), GetError>

Get a unique reference to an object with its associated singleton state

Panics

Panics if AnyObject::type_id or AnyObject::new_singleton_state is not properly implemented for O.

source

fn get<T: 'static>(&self, id: u32) -> Result<&T, GetError>

Get a reference to an object from the store, and cast it down to the concrete type.

source

fn get_mut<T: 'static>(&mut self, id: u32) -> Result<&mut T, GetError>

Get a unique reference to an object from the store, and cast it down to the concrete type.

source

fn contains(&self, id: u32) -> bool

Returns whether the store contains a given ID

source

fn try_insert_with(&mut self, id: u32, f: impl FnOnce() -> O) -> Option<&mut O>

Try to insert an object into the store with the given ID, the object is created by calling the closure f. f is never called if the ID already exists in the store.

source

fn try_insert_with_state<T: Into<O> + MonoObject + 'static>( &mut self, id: u32, f: impl FnOnce(&mut T::SingletonState) -> T ) -> Option<(&mut T, &mut T::SingletonState)>

Try to insert an object into the store with the given ID, the object is created by calling the closure f with the singleton state that’s associated with the object type. f is never called if the ID already exists in the store.

source

fn by_type<T: MonoObject + 'static>(&self) -> Self::ByType<'_, T>

Returns an iterator for all objects in the store with a specific type.

source

fn ids_by_type<T: 'static>(&self) -> Self::IdsByType<'_, T>

Returns an iterator that yields all the object IDs for objects in the store with a specific type.

Implementors§

source§

impl<O: AnyObject> Store<O> for Store<O>

§

type ByType<'a, T> where O: 'a, T: MonoObject + 'a = impl Iterator<Item = (u32, &'a T)> + 'a

§

type IdsByType<'a, T> where O: 'a, T: 'static = impl Iterator<Item = u32> + 'a