Struct cacao::utils::CellFactory
source · [−]Expand description
A CellFactory is an struct that stores closures that instantiate view types.
This is a pattern used in certain view types (e.g, ListView
). This factory exists to enable
dynamic view registration and dequeueing. It stores a closure and erases the type to Any
, and
supports querying for that time to get it back.
It is explicitly designed to panic if it’s unable to retrieve a stored item with the specified type, as the views that use this would cease to function if the type can’t be retrieved, and it’s better to blow up early.
Tuple Fields
0: Rc<RefCell<HashMap<&'static str, Box<dyn Fn() -> Box<dyn Any>>>>>
Implementations
sourceimpl CellFactory
impl CellFactory
sourcepub fn insert<F, T>(&self, identifier: &'static str, vendor: F) where
F: Fn() -> T + 'static,
T: ViewDelegate + 'static,
pub fn insert<F, T>(&self, identifier: &'static str, vendor: F) where
F: Fn() -> T + 'static,
T: ViewDelegate + 'static,
Store a closure for the given identifier.
sourcepub fn get<R>(&self, identifier: &'static str) -> Box<R> where
R: ViewDelegate + 'static,
pub fn get<R>(&self, identifier: &'static str) -> Box<R> where
R: ViewDelegate + 'static,
Attempts to retrieve the closure, downcasted to the specified type. This will panic if it’s unable to retrieve the closure with the requested type.
Trait Implementations
sourceimpl Clone for CellFactory
impl Clone for CellFactory
sourcefn clone(&self) -> CellFactory
fn clone(&self) -> CellFactory
Returns a copy of the value. Read more
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source
. Read more
Auto Trait Implementations
impl !RefUnwindSafe for CellFactory
impl !Send for CellFactory
impl !Sync for CellFactory
impl Unpin for CellFactory
impl !UnwindSafe for CellFactory
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more