Struct changed::Cd[][src]

pub struct Cd<T> { /* fields omitted */ }
Expand description

Cd: Change Detection

Start by creating one with new().

Implementations

Create a new Cd with data. It is initialized to false for change detection.

use changed::Cd;
let cd = Cd::new(5);

Create a new Cd with data. It is initialized to true for change detection.

use changed::Cd;
let cd = Cd::new_true(5);
assert!(cd.changed());

Reset the change tracking to false.

use changed::Cd;
let mut cd = Cd::new_true(5);
cd.reset();
assert!(!cd.changed());

Take the data out of the Cd. Consumes self and returns data.

use changed::Cd;
let cd = Cd::new(5);
let data = cd.take();
// Error: cd has been moved.
// cd.changed();

Check if the Cd has been changed since the last call to reset (or created.)

use changed::Cd;
let mut cd = Cd::new(5);
assert!(!cd.changed());
*cd += 5;
assert!(cd.changed());

Mutate the Cd without tripping change detection.

use changed::Cd;
let mut cd = Cd::new(5);
*cd.mutate_silently() += 5;
assert!(!cd.changed());

Trait Implementations

Impl default where the data impls default. Change detection is initialized to false.

use changed::Cd;
// 0 is default for i32.
let zero: Cd<i32> = Cd::default();
assert!(!zero.changed());

Returns the “default value” for a type. Read more

deref does not trip change detection.

use changed::Cd;
let cd = Cd::new(5);
assert_eq!(*cd, 5); // deref for == 5
assert!(!cd.changed()); // .changed() is false

The resulting type after dereferencing.

Dereferences the value.

deref_mut trips change detection.

use changed::Cd;
let mut cd = Cd::new(5);
*cd += 5; // deref_mut for add assign
assert_eq!(*cd, 10);
assert!(cd.changed()); // .changed() is true

Mutably dereferences the value.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.