Struct suzy::watch::Watched [−][src]
This represents some value which will be interesting to watch. Watcher functions that reference this value will be re-run when this value changes.
Implementations
impl<T> Watched<T>
[src]
pub fn new(value: T) -> Watched<T>
[src]
Create a new watched value.
pub fn into_inner(self) -> T
[src]
Consumes the Watched
, returning the wrapped value
pub fn replace(&mut self, value: T) -> T
[src]
Replaces the wrapped value with a new one, returning the old value, without deinitializing either one.
impl<T> Watched<T> where
T: ?Sized,
[src]
T: ?Sized,
pub fn get_unwatched(this: &Watched<T>) -> &T
[src]
Get a referenced to the wrapped value, without binding the current watch closure.
impl<T> Watched<T> where
T: Default,
[src]
T: Default,
impl<T> Watched<T> where
T: PartialEq<T>,
[src]
T: PartialEq<T>,
pub fn set_if_neq(wrapper: &mut Watched<T>, value: T)
[src]
This function provides a way to set a value for a watched value only if is has changed. This is useful for cases where setting a value would otherwise cause an infinite loop.
Examples
The following example uses the watch system to keep two variables in sync. This would normally cause an infinite loop as each update of one would cause the other one to re-evaluate. However using set_if_neq allows it to detect that the value is the same and stop propogating.
#[derive(Default)] struct KeepBalanced { left: Watched<i32>, right: Watched<i32>, } impl WatcherInit for KeepBalanced { fn init(watcher: &mut WatcherMeta<Self>) { watcher.watch(|root| { Watched::set_if_neq(&mut root.left, *root.right); }); watcher.watch(|root| { Watched::set_if_neq(&mut root.right, *root.left); }); } } fn main() { let mut ctx = WatchContext::new(); ctx.set_frame_limit(Some(100)); ctx.with(|| { let obj = WatchContext::allow_watcher_access((), |()| { let mut obj = Watcher::<KeepBalanced>::new(); *obj.data_mut().left = 68; obj }); WatchContext::update_current(); WatchContext::allow_watcher_access(obj, |obj| { assert_eq!(*obj.data().right, 68); }); }); }
Trait Implementations
impl<'a, T, U> Add<U> for &'a Watched<T> where
T: ?Sized,
&'a T: Add<U>,
[src]
T: ?Sized,
&'a T: Add<U>,
type Output = <&'a T as Add<U>>::Output
The resulting type after applying the +
operator.
pub fn add(self, other: U) -> <&'a T as Add<U>>::Output
[src]
impl<T, U> Add<U> for Watched<T> where
T: Add<U>,
[src]
T: Add<U>,
type Output = <T as Add<U>>::Output
The resulting type after applying the +
operator.
pub fn add(self, other: U) -> <T as Add<U>>::Output
[src]
impl<T, U> AddAssign<U> for Watched<T> where
T: AddAssign<U> + ?Sized,
[src]
T: AddAssign<U> + ?Sized,
pub fn add_assign(&mut self, rhs: U)
[src]
impl<'a, T, U> BitAnd<U> for &'a Watched<T> where
T: ?Sized,
&'a T: BitAnd<U>,
[src]
T: ?Sized,
&'a T: BitAnd<U>,
type Output = <&'a T as BitAnd<U>>::Output
The resulting type after applying the &
operator.
pub fn bitand(self, other: U) -> <&'a T as BitAnd<U>>::Output
[src]
impl<T, U> BitAnd<U> for Watched<T> where
T: BitAnd<U>,
[src]
T: BitAnd<U>,
type Output = <T as BitAnd<U>>::Output
The resulting type after applying the &
operator.
pub fn bitand(self, other: U) -> <T as BitAnd<U>>::Output
[src]
impl<T, U> BitAndAssign<U> for Watched<T> where
T: BitAndAssign<U> + ?Sized,
[src]
T: BitAndAssign<U> + ?Sized,
pub fn bitand_assign(&mut self, rhs: U)
[src]
impl<T, U> BitOr<U> for Watched<T> where
T: BitOr<U>,
[src]
T: BitOr<U>,
type Output = <T as BitOr<U>>::Output
The resulting type after applying the |
operator.
pub fn bitor(self, other: U) -> <T as BitOr<U>>::Output
[src]
impl<'a, T, U> BitOr<U> for &'a Watched<T> where
T: ?Sized,
&'a T: BitOr<U>,
[src]
T: ?Sized,
&'a T: BitOr<U>,
type Output = <&'a T as BitOr<U>>::Output
The resulting type after applying the |
operator.
pub fn bitor(self, other: U) -> <&'a T as BitOr<U>>::Output
[src]
impl<T, U> BitOrAssign<U> for Watched<T> where
T: BitOrAssign<U> + ?Sized,
[src]
T: BitOrAssign<U> + ?Sized,
pub fn bitor_assign(&mut self, rhs: U)
[src]
impl<T, U> BitXor<U> for Watched<T> where
T: BitXor<U>,
[src]
T: BitXor<U>,
type Output = <T as BitXor<U>>::Output
The resulting type after applying the ^
operator.
pub fn bitxor(self, other: U) -> <T as BitXor<U>>::Output
[src]
impl<'a, T, U> BitXor<U> for &'a Watched<T> where
T: ?Sized,
&'a T: BitXor<U>,
[src]
T: ?Sized,
&'a T: BitXor<U>,
type Output = <&'a T as BitXor<U>>::Output
The resulting type after applying the ^
operator.
pub fn bitxor(self, other: U) -> <&'a T as BitXor<U>>::Output
[src]
impl<T, U> BitXorAssign<U> for Watched<T> where
T: BitXorAssign<U> + ?Sized,
[src]
T: BitXorAssign<U> + ?Sized,
pub fn bitxor_assign(&mut self, rhs: U)
[src]
impl<T> Clone for Watched<T> where
T: Clone,
[src]
T: Clone,
impl<T> Debug for Watched<T> where
T: Debug + ?Sized,
[src]
T: Debug + ?Sized,
impl<T> Default for Watched<T> where
T: Default,
[src]
T: Default,
impl<T> Deref for Watched<T> where
T: ?Sized,
[src]
T: ?Sized,
impl<T> DerefMut for Watched<T> where
T: ?Sized,
[src]
T: ?Sized,
impl<T> Display for Watched<T> where
T: Display + ?Sized,
[src]
T: Display + ?Sized,
impl<'a, T, U> Div<U> for &'a Watched<T> where
T: ?Sized,
&'a T: Div<U>,
[src]
T: ?Sized,
&'a T: Div<U>,
type Output = <&'a T as Div<U>>::Output
The resulting type after applying the /
operator.
pub fn div(self, other: U) -> <&'a T as Div<U>>::Output
[src]
impl<T, U> Div<U> for Watched<T> where
T: Div<U>,
[src]
T: Div<U>,
type Output = <T as Div<U>>::Output
The resulting type after applying the /
operator.
pub fn div(self, other: U) -> <T as Div<U>>::Output
[src]
impl<T, U> DivAssign<U> for Watched<T> where
T: DivAssign<U> + ?Sized,
[src]
T: DivAssign<U> + ?Sized,
pub fn div_assign(&mut self, rhs: U)
[src]
impl<T, U> Mul<U> for Watched<T> where
T: Mul<U>,
[src]
T: Mul<U>,
type Output = <T as Mul<U>>::Output
The resulting type after applying the *
operator.
pub fn mul(self, other: U) -> <T as Mul<U>>::Output
[src]
impl<'a, T, U> Mul<U> for &'a Watched<T> where
T: ?Sized,
&'a T: Mul<U>,
[src]
T: ?Sized,
&'a T: Mul<U>,
type Output = <&'a T as Mul<U>>::Output
The resulting type after applying the *
operator.
pub fn mul(self, other: U) -> <&'a T as Mul<U>>::Output
[src]
impl<T, U> MulAssign<U> for Watched<T> where
T: MulAssign<U> + ?Sized,
[src]
T: MulAssign<U> + ?Sized,
pub fn mul_assign(&mut self, rhs: U)
[src]
impl<'a, T> Neg for &'a Watched<T> where
T: ?Sized,
&'a T: Neg,
[src]
T: ?Sized,
&'a T: Neg,
type Output = <&'a T as Neg>::Output
The resulting type after applying the -
operator.
pub fn neg(self) -> <&'a T as Neg>::Output
[src]
impl<T> Neg for Watched<T> where
T: Neg,
[src]
T: Neg,
type Output = <T as Neg>::Output
The resulting type after applying the -
operator.
pub fn neg(self) -> <T as Neg>::Output
[src]
impl<'a, T> Not for &'a Watched<T> where
T: ?Sized,
&'a T: Not,
[src]
T: ?Sized,
&'a T: Not,
type Output = <&'a T as Not>::Output
The resulting type after applying the !
operator.
pub fn not(self) -> <&'a T as Not>::Output
[src]
impl<T> Not for Watched<T> where
T: Not,
[src]
T: Not,
type Output = <T as Not>::Output
The resulting type after applying the !
operator.
pub fn not(self) -> <T as Not>::Output
[src]
impl<T, U> PartialEq<U> for Watched<T> where
T: PartialEq<U> + ?Sized,
U: ?Sized,
[src]
T: PartialEq<U> + ?Sized,
U: ?Sized,
impl<T, U> PartialOrd<U> for Watched<T> where
T: PartialOrd<U> + ?Sized,
U: ?Sized,
[src]
T: PartialOrd<U> + ?Sized,
U: ?Sized,
pub fn partial_cmp(&self, other: &U) -> Option<Ordering>
[src]
pub fn lt(&self, other: &U) -> bool
[src]
pub fn le(&self, other: &U) -> bool
[src]
pub fn ge(&self, other: &U) -> bool
[src]
pub fn gt(&self, other: &U) -> bool
[src]
impl<T, U> Rem<U> for Watched<T> where
T: Rem<U>,
[src]
T: Rem<U>,
type Output = <T as Rem<U>>::Output
The resulting type after applying the %
operator.
pub fn rem(self, other: U) -> <T as Rem<U>>::Output
[src]
impl<'a, T, U> Rem<U> for &'a Watched<T> where
T: ?Sized,
&'a T: Rem<U>,
[src]
T: ?Sized,
&'a T: Rem<U>,
type Output = <&'a T as Rem<U>>::Output
The resulting type after applying the %
operator.
pub fn rem(self, other: U) -> <&'a T as Rem<U>>::Output
[src]
impl<T, U> RemAssign<U> for Watched<T> where
T: RemAssign<U> + ?Sized,
[src]
T: RemAssign<U> + ?Sized,
pub fn rem_assign(&mut self, rhs: U)
[src]
impl<T, U> Shl<U> for Watched<T> where
T: Shl<U>,
[src]
T: Shl<U>,
type Output = <T as Shl<U>>::Output
The resulting type after applying the <<
operator.
pub fn shl(self, other: U) -> <T as Shl<U>>::Output
[src]
impl<'a, T, U> Shl<U> for &'a Watched<T> where
T: ?Sized,
&'a T: Shl<U>,
[src]
T: ?Sized,
&'a T: Shl<U>,
type Output = <&'a T as Shl<U>>::Output
The resulting type after applying the <<
operator.
pub fn shl(self, other: U) -> <&'a T as Shl<U>>::Output
[src]
impl<T, U> ShlAssign<U> for Watched<T> where
T: ShlAssign<U> + ?Sized,
[src]
T: ShlAssign<U> + ?Sized,
pub fn shl_assign(&mut self, rhs: U)
[src]
impl<T, U> Shr<U> for Watched<T> where
T: Shr<U>,
[src]
T: Shr<U>,
type Output = <T as Shr<U>>::Output
The resulting type after applying the >>
operator.
pub fn shr(self, other: U) -> <T as Shr<U>>::Output
[src]
impl<'a, T, U> Shr<U> for &'a Watched<T> where
T: ?Sized,
&'a T: Shr<U>,
[src]
T: ?Sized,
&'a T: Shr<U>,
type Output = <&'a T as Shr<U>>::Output
The resulting type after applying the >>
operator.
pub fn shr(self, other: U) -> <&'a T as Shr<U>>::Output
[src]
impl<T, U> ShrAssign<U> for Watched<T> where
T: ShrAssign<U> + ?Sized,
[src]
T: ShrAssign<U> + ?Sized,
pub fn shr_assign(&mut self, rhs: U)
[src]
impl<T, U> Sub<U> for Watched<T> where
T: Sub<U>,
[src]
T: Sub<U>,
type Output = <T as Sub<U>>::Output
The resulting type after applying the -
operator.
pub fn sub(self, other: U) -> <T as Sub<U>>::Output
[src]
impl<'a, T, U> Sub<U> for &'a Watched<T> where
T: ?Sized,
&'a T: Sub<U>,
[src]
T: ?Sized,
&'a T: Sub<U>,
type Output = <&'a T as Sub<U>>::Output
The resulting type after applying the -
operator.
pub fn sub(self, other: U) -> <&'a T as Sub<U>>::Output
[src]
impl<T, U> SubAssign<U> for Watched<T> where
T: SubAssign<U> + ?Sized,
[src]
T: SubAssign<U> + ?Sized,
pub fn sub_assign(&mut self, rhs: U)
[src]
Auto Trait Implementations
impl<T> !RefUnwindSafe for Watched<T>
impl<T> !Send for Watched<T>
impl<T> !Sync for Watched<T>
impl<T: ?Sized> Unpin for Watched<T> where
T: Unpin,
T: Unpin,
impl<T> !UnwindSafe for Watched<T>
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn clone_into(&self, target: &mut T)
[src]
impl<T> ToString for T where
T: Display + ?Sized,
[src]
T: Display + ?Sized,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,