pub trait NeqAssign<NEW> {
// Required method
fn neq_assign(&mut self, new: NEW) -> ShouldRender;
}
Expand description
Blanket trait to provide a convenience method for assigning props in changed
or updating values in update
.
Required Methods§
Sourcefn neq_assign(&mut self, new: NEW) -> ShouldRender
fn neq_assign(&mut self, new: NEW) -> ShouldRender
If self
and new
aren’t equal, assigns new
to self
and returns true, otherwise returns false.
Short for “Not equal assign”.
§Example
#[derive(Clone, Properties, PartialEq)]
struct Props {
field1: String,
field2: usize
}
struct Model {
props: Props
}
impl Component for Model {
type Properties = Props;
// ...
fn change(&mut self, props: Self::Properties) -> ShouldRender{
self.props.neq_assign(props)
}
}
let mut foo = 1;
assert_eq!(foo.neq_assign(42), true);
assert_eq!(foo, 42);
assert_eq!(foo.neq_assign(42), false);