Struct suzy::watch::Watched[][src]

pub struct Watched<T> where
    T: ?Sized
{ /* fields omitted */ }

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]

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]

pub fn take(&mut self) -> T[src]

Takes the wrapped value, leaving Default::default() in its place.

impl<T> Watched<T> where
    T: PartialEq<T>, 
[src]

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]

type Output = <&'a T as Add<U>>::Output

The resulting type after applying the + operator.

impl<T, U> Add<U> for Watched<T> where
    T: Add<U>, 
[src]

type Output = <T as Add<U>>::Output

The resulting type after applying the + operator.

impl<T, U> AddAssign<U> for Watched<T> where
    T: AddAssign<U> + ?Sized
[src]

impl<'a, T, U> BitAnd<U> for &'a Watched<T> where
    T: ?Sized,
    &'a T: BitAnd<U>, 
[src]

type Output = <&'a T as BitAnd<U>>::Output

The resulting type after applying the & operator.

impl<T, U> BitAnd<U> for Watched<T> where
    T: BitAnd<U>, 
[src]

type Output = <T as BitAnd<U>>::Output

The resulting type after applying the & operator.

impl<T, U> BitAndAssign<U> for Watched<T> where
    T: BitAndAssign<U> + ?Sized
[src]

impl<T, U> BitOr<U> for Watched<T> where
    T: BitOr<U>, 
[src]

type Output = <T as BitOr<U>>::Output

The resulting type after applying the | operator.

impl<'a, T, U> BitOr<U> for &'a Watched<T> where
    T: ?Sized,
    &'a T: BitOr<U>, 
[src]

type Output = <&'a T as BitOr<U>>::Output

The resulting type after applying the | operator.

impl<T, U> BitOrAssign<U> for Watched<T> where
    T: BitOrAssign<U> + ?Sized
[src]

impl<T, U> BitXor<U> for Watched<T> where
    T: BitXor<U>, 
[src]

type Output = <T as BitXor<U>>::Output

The resulting type after applying the ^ operator.

impl<'a, T, U> BitXor<U> for &'a Watched<T> where
    T: ?Sized,
    &'a T: BitXor<U>, 
[src]

type Output = <&'a T as BitXor<U>>::Output

The resulting type after applying the ^ operator.

impl<T, U> BitXorAssign<U> for Watched<T> where
    T: BitXorAssign<U> + ?Sized
[src]

impl<T> Clone for Watched<T> where
    T: Clone
[src]

impl<T> Debug for Watched<T> where
    T: Debug + ?Sized
[src]

impl<T> Default for Watched<T> where
    T: Default
[src]

impl<T> Deref for Watched<T> where
    T: ?Sized
[src]

type Target = T

The resulting type after dereferencing.

impl<T> DerefMut for Watched<T> where
    T: ?Sized
[src]

impl<T> Display for Watched<T> where
    T: Display + ?Sized
[src]

impl<'a, T, U> Div<U> for &'a Watched<T> where
    T: ?Sized,
    &'a T: Div<U>, 
[src]

type Output = <&'a T as Div<U>>::Output

The resulting type after applying the / operator.

impl<T, U> Div<U> for Watched<T> where
    T: Div<U>, 
[src]

type Output = <T as Div<U>>::Output

The resulting type after applying the / operator.

impl<T, U> DivAssign<U> for Watched<T> where
    T: DivAssign<U> + ?Sized
[src]

impl<T, U> Mul<U> for Watched<T> where
    T: Mul<U>, 
[src]

type Output = <T as Mul<U>>::Output

The resulting type after applying the * operator.

impl<'a, T, U> Mul<U> for &'a Watched<T> where
    T: ?Sized,
    &'a T: Mul<U>, 
[src]

type Output = <&'a T as Mul<U>>::Output

The resulting type after applying the * operator.

impl<T, U> MulAssign<U> for Watched<T> where
    T: MulAssign<U> + ?Sized
[src]

impl<'a, T> Neg for &'a Watched<T> where
    T: ?Sized,
    &'a T: Neg
[src]

type Output = <&'a T as Neg>::Output

The resulting type after applying the - operator.

impl<T> Neg for Watched<T> where
    T: Neg
[src]

type Output = <T as Neg>::Output

The resulting type after applying the - operator.

impl<'a, T> Not for &'a Watched<T> where
    T: ?Sized,
    &'a T: Not
[src]

type Output = <&'a T as Not>::Output

The resulting type after applying the ! operator.

impl<T> Not for Watched<T> where
    T: Not
[src]

type Output = <T as Not>::Output

The resulting type after applying the ! operator.

impl<T, U> PartialEq<U> for Watched<T> where
    T: PartialEq<U> + ?Sized,
    U: ?Sized
[src]

impl<T, U> PartialOrd<U> for Watched<T> where
    T: PartialOrd<U> + ?Sized,
    U: ?Sized
[src]

impl<T, U> Rem<U> for Watched<T> where
    T: Rem<U>, 
[src]

type Output = <T as Rem<U>>::Output

The resulting type after applying the % operator.

impl<'a, T, U> Rem<U> for &'a Watched<T> where
    T: ?Sized,
    &'a T: Rem<U>, 
[src]

type Output = <&'a T as Rem<U>>::Output

The resulting type after applying the % operator.

impl<T, U> RemAssign<U> for Watched<T> where
    T: RemAssign<U> + ?Sized
[src]

impl<T, U> Shl<U> for Watched<T> where
    T: Shl<U>, 
[src]

type Output = <T as Shl<U>>::Output

The resulting type after applying the << operator.

impl<'a, T, U> Shl<U> for &'a Watched<T> where
    T: ?Sized,
    &'a T: Shl<U>, 
[src]

type Output = <&'a T as Shl<U>>::Output

The resulting type after applying the << operator.

impl<T, U> ShlAssign<U> for Watched<T> where
    T: ShlAssign<U> + ?Sized
[src]

impl<T, U> Shr<U> for Watched<T> where
    T: Shr<U>, 
[src]

type Output = <T as Shr<U>>::Output

The resulting type after applying the >> operator.

impl<'a, T, U> Shr<U> for &'a Watched<T> where
    T: ?Sized,
    &'a T: Shr<U>, 
[src]

type Output = <&'a T as Shr<U>>::Output

The resulting type after applying the >> operator.

impl<T, U> ShrAssign<U> for Watched<T> where
    T: ShrAssign<U> + ?Sized
[src]

impl<T, U> Sub<U> for Watched<T> where
    T: Sub<U>, 
[src]

type Output = <T as Sub<U>>::Output

The resulting type after applying the - operator.

impl<'a, T, U> Sub<U> for &'a Watched<T> where
    T: ?Sized,
    &'a T: Sub<U>, 
[src]

type Output = <&'a T as Sub<U>>::Output

The resulting type after applying the - operator.

impl<T, U> SubAssign<U> for Watched<T> where
    T: SubAssign<U> + ?Sized
[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

impl<T> !UnwindSafe for Watched<T>

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T> ToString for T where
    T: Display + ?Sized
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.