[−][src]Struct drying_paint::Watched
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) -> Self
[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: Default> Watched<T>
[src]
impl<T: PartialEq> Watched<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<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.
fn add(self, other: U) -> <T as Add<U>>::Output
[src]
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.
fn add(self, other: U) -> <&'a T as Add<U>>::Output
[src]
impl<T: ?Sized, U> AddAssign<U> for Watched<T> where
T: AddAssign<U>,
[src]
T: AddAssign<U>,
fn add_assign(&mut self, rhs: U)
[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.
fn bitand(self, other: U) -> <T as BitAnd<U>>::Output
[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.
fn bitand(self, other: U) -> <&'a T as BitAnd<U>>::Output
[src]
impl<T: ?Sized, U> BitAndAssign<U> for Watched<T> where
T: BitAndAssign<U>,
[src]
T: BitAndAssign<U>,
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.
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.
fn bitor(self, other: U) -> <&'a T as BitOr<U>>::Output
[src]
impl<T: ?Sized, U> BitOrAssign<U> for Watched<T> where
T: BitOrAssign<U>,
[src]
T: BitOrAssign<U>,
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.
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.
fn bitxor(self, other: U) -> <&'a T as BitXor<U>>::Output
[src]
impl<T: ?Sized, U> BitXorAssign<U> for Watched<T> where
T: BitXorAssign<U>,
[src]
T: BitXorAssign<U>,
fn bitxor_assign(&mut self, rhs: U)
[src]
impl<T: Clone> Clone for Watched<T>
[src]
impl<T: Debug + ?Sized> Debug for Watched<T>
[src]
impl<T: Default> Default for Watched<T>
[src]
impl<T: ?Sized> Deref for Watched<T>
[src]
impl<T: ?Sized> DerefMut for Watched<T>
[src]
impl<T: Display + ?Sized> Display for Watched<T>
[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.
fn div(self, other: U) -> <T as Div<U>>::Output
[src]
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.
fn div(self, other: U) -> <&'a T as Div<U>>::Output
[src]
impl<T: ?Sized, U> DivAssign<U> for Watched<T> where
T: DivAssign<U>,
[src]
T: DivAssign<U>,
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.
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.
fn mul(self, other: U) -> <&'a T as Mul<U>>::Output
[src]
impl<T: ?Sized, U> MulAssign<U> for Watched<T> where
T: MulAssign<U>,
[src]
T: MulAssign<U>,
fn mul_assign(&mut self, rhs: U)
[src]
impl<T: Neg> Neg for Watched<T>
[src]
type Output = <T as Neg>::Output
The resulting type after applying the -
operator.
fn neg(self) -> <T as Neg>::Output
[src]
impl<'a, T: ?Sized> Neg for &'a Watched<T> where
&'a T: Neg,
[src]
&'a T: Neg,
type Output = <&'a T as Neg>::Output
The resulting type after applying the -
operator.
fn neg(self) -> <&'a T as Neg>::Output
[src]
impl<T: Not> Not for Watched<T>
[src]
type Output = <T as Not>::Output
The resulting type after applying the !
operator.
fn not(self) -> <T as Not>::Output
[src]
impl<'a, T: ?Sized> Not for &'a Watched<T> where
&'a T: Not,
[src]
&'a T: Not,
type Output = <&'a T as Not>::Output
The resulting type after applying the !
operator.
fn not(self) -> <&'a T as Not>::Output
[src]
impl<T: ?Sized, U> PartialEq<U> for Watched<T> where
T: PartialEq<U>,
U: ?Sized,
[src]
T: PartialEq<U>,
U: ?Sized,
impl<T: ?Sized, U> PartialOrd<U> for Watched<T> where
T: PartialOrd<U>,
U: ?Sized,
[src]
T: PartialOrd<U>,
U: ?Sized,
fn partial_cmp(&self, other: &U) -> Option<Ordering>
[src]
fn lt(&self, other: &U) -> bool
[src]
fn le(&self, other: &U) -> bool
[src]
fn ge(&self, other: &U) -> bool
[src]
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.
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.
fn rem(self, other: U) -> <&'a T as Rem<U>>::Output
[src]
impl<T: ?Sized, U> RemAssign<U> for Watched<T> where
T: RemAssign<U>,
[src]
T: RemAssign<U>,
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.
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.
fn shl(self, other: U) -> <&'a T as Shl<U>>::Output
[src]
impl<T: ?Sized, U> ShlAssign<U> for Watched<T> where
T: ShlAssign<U>,
[src]
T: ShlAssign<U>,
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.
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.
fn shr(self, other: U) -> <&'a T as Shr<U>>::Output
[src]
impl<T: ?Sized, U> ShrAssign<U> for Watched<T> where
T: ShrAssign<U>,
[src]
T: ShrAssign<U>,
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.
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.
fn sub(self, other: U) -> <&'a T as Sub<U>>::Output
[src]
impl<T: ?Sized, U> SubAssign<U> for Watched<T> where
T: SubAssign<U>,
[src]
T: SubAssign<U>,
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,
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.
fn to_owned(&self) -> T
[src]
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.
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>,