pub trait AttributeUpdate:
Sized
+ Send
+ Sync
+ Clone
+ Copy {
// Required methods
fn merge(attr1: Self, attr2: Self) -> Self;
fn split(attr: Self) -> (Self, Self);
// Provided methods
fn merge_incomplete(attr: Self) -> Self { ... }
fn merge_from_none() -> Option<Self> { ... }
}
Expand description
Generic attribute trait for logical behavior description
This trait can be implemented for a given attribute in order to define the behavior to follow when (un)sewing operations result in an update of the attribute.
§Example
For an intensive property of a system (e.g. a temperature), an implementation would look like this:
use honeycomb_core::prelude::AttributeUpdate;
#[derive(Clone, Copy, Debug, PartialEq)]
pub struct Temperature {
pub val: f32
}
impl AttributeUpdate for Temperature {
fn merge(attr1: Self, attr2: Self) -> Self {
Temperature { val: (attr1.val + attr2.val) / 2.0 }
}
fn split(attr: Self) -> (Self, Self) {
(attr, attr)
}
fn merge_incomplete(attr: Self) -> Self {
Temperature { val: attr.val / 2.0 }
}
fn merge_from_none() -> Option<Self> {
Some(Temperature { val: 0.0 })
}
}
let t1 = Temperature { val: 273.0 };
let t2 = Temperature { val: 298.0 };
let t_new = AttributeUpdate::merge(t1, t2); // use AttributeUpdate::_
let t_ref = Temperature { val: 285.5 };
assert_eq!(Temperature::split(t_new), (t_ref, t_ref)); // or Temperature::_
Required Methods§
Provided Methods§
Sourcefn merge_incomplete(attr: Self) -> Self
fn merge_incomplete(attr: Self) -> Self
Fallback merging routine, i.e. how to obtain the new attribute value from a single existing value.
The default implementation simply returns the passed value.
Sourcefn merge_from_none() -> Option<Self>
fn merge_from_none() -> Option<Self>
Fallback merging routine, i.e. how to obtain the new attribute value from no existing value.
The default implementation return None
.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.
Implementors§
impl<T: CoordsFloat> AttributeUpdate for Vertex2<T>
Attribute logic definitions
- MERGING POLICY - The new vertex is placed at the midpoint between the two existing ones.
- SPLITTING POLICY - The current vertex is duplicated.
- (PARTIALLY) UNDEFINED ATTRIBUTES MERGING - The default implementations are used.
impl<T: CoordsFloat> AttributeUpdate for Vertex3<T>
Attribute logic definitions
- MERGING POLICY - The new vertex is placed at the midpoint between the two existing ones.
- SPLITTING POLICY - The current vertex is duplicated.
- (PARTIALLY) UNDEFINED ATTRIBUTES MERGING - The default implementations are used.