pub struct StateBinding<T: State> { /* private fields */ }Expand description
Typed state binding for editors.
Wraps the get_state/set_state closures from PluginContext with
typed serialization. Caches the deserialized state to avoid repeated
deserialization each frame.
ⓘ
struct MyEditor {
state: StateBinding<PersistentState>,
}
// In open():
self.state = StateBinding::new(&context);
// In state_changed():
self.state.sync();
// Reading:
let name = &self.state.get().instance_name;
// Writing:
self.state.update(|s| s.instance_name = new_name);Implementations§
Source§impl<T: State> StateBinding<T>
impl<T: State> StateBinding<T>
Sourcepub fn new<P: ?Sized>(context: &PluginContext<P>) -> Self
pub fn new<P: ?Sized>(context: &PluginContext<P>) -> Self
Create a new binding from a PluginContext. Generic over the
context’s <P> since StateBinding cares only about the
get_state / set_state channel on the underlying
EditorBridge, never about parameter typing.
Trait Implementations§
Source§impl<T: State> Default for StateBinding<T>
impl<T: State> Default for StateBinding<T>
Source§fn default() -> Self
fn default() -> Self
Construct an unwired binding: get() returns T::default()
and update() silently discards the new state. Only useful
as a placeholder before the editor is opened; replace with
StateBinding::new(&context) inside
Editor::open once a PluginContext is available. If you
see writes vanishing, check that the binding has been wired up
before you call update.
Auto Trait Implementations§
impl<T> Freeze for StateBinding<T>where
T: Freeze,
impl<T> !RefUnwindSafe for StateBinding<T>
impl<T> Send for StateBinding<T>where
T: Send,
impl<T> Sync for StateBinding<T>where
T: Sync,
impl<T> Unpin for StateBinding<T>where
T: Unpin,
impl<T> UnsafeUnpin for StateBinding<T>where
T: UnsafeUnpin,
impl<T> !UnwindSafe for StateBinding<T>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more