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

Method with_state

aspen/src/context_stack/event_context.rs:159–176  ·  view source on GitHub ↗
(
        &mut self,
        callback: impl FnOnce(&mut State, &mut EventContext<'a>) -> Result,
    )

Source from the content-addressed store, hash-verified

157 }
158
159 pub fn with_state<State: Any + Default, Result>(
160 &mut self,
161 callback: impl FnOnce(&mut State, &mut EventContext<'a>) -> Result,
162 ) -> Result {
163 let mut states = self.states.borrow_mut();
164 let state = match states.entry(self.element_token) {
165 Entry::Occupied(entry) => entry
166 .into_mut()
167 .downcast_mut()
168 .expect("Tried to get state with different type than was previously inserted"),
169 Entry::Vacant(entry) => entry
170 .insert(Box::new(State::default()))
171 .downcast_mut()
172 .unwrap(),
173 };
174
175 callback(state, self)
176 }
177
178 pub fn for_region<'b>(&'b mut self, region: &'b MouseRegion) -> EventContext<'b> {
179 let child_cx: AttachedContext<'b> = self

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected