MCPcopy Create free account
hub / github.com/Kethku/Pando / with_state

Method with_state

aspen/src/context_stack/draw_context.rs:448–463  ·  view source on GitHub ↗
(
        &mut self,
        callback: impl FnOnce(&mut State, &mut DrawContext<'a>) -> Result,
    )

Source from the content-addressed store, hash-verified

446 }
447
448 pub fn with_state<State: Any + Default, Result>(
449 &mut self,
450 callback: impl FnOnce(&mut State, &mut DrawContext<'a>) -> Result,
451 ) -> Result {
452 let mut states = self.states.borrow_mut();
453 let state = match states.entry(self.element_token) {
454 Entry::Occupied(entry) => {
455 entry.into_mut().downcast_mut().expect("Tried to get state with different type than was previously inserted")
456 },
457 Entry::Vacant(entry) => {
458 entry.insert(Box::new(State::default())).downcast_mut().unwrap()
459 }
460 };
461
462 callback(state, self)
463 }
464
465 pub(crate) fn child<'b>(
466 &'b mut self,

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected