Skip to content

Commit

Permalink
#53 Add Deref and DerefMut for StateHandle
Browse files Browse the repository at this point in the history
  • Loading branch information
wtholliday committed Dec 13, 2023
1 parent ec4d8dc commit 22d7e57
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion src/views/state.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::*;
use std::any::Any;
use std::{any::Any, ops::Deref, ops::DerefMut};

/// Weak reference to app state.
///
Expand Down Expand Up @@ -43,6 +43,21 @@ impl<S: 'static> Binding<S> for StateHandle<S> {
}
}

impl<S: 'static> Deref for StateHandle<S> {

type Target = S;

fn deref(&self) -> &Self::Target {
unsafe { &(*self.cx)[*self] }
}
}

impl<S: 'static> DerefMut for StateHandle<S> {
fn deref_mut(&mut self) -> &mut Self::Target {
unsafe { &mut (*self.cx)[*self] }
}
}

#[derive(Clone)]
struct StateView<D, F> {
default: D,
Expand Down

0 comments on commit 22d7e57

Please sign in to comment.