pub trait Property<E: Entity>: AnyProperty {
type CanonicalValue: AnyProperty;
Show 16 methods
// Required methods
fn initialization_kind() -> PropertyInitializationKind;
fn compute_derived(context: &Context, entity_id: EntityId<E>) -> Self;
fn default_const() -> Self;
fn make_canonical(self) -> Self::CanonicalValue;
fn make_uncanonical(value: Self::CanonicalValue) -> Self;
fn get_display(&self) -> String;
fn id() -> usize;
fn collect_non_derived_dependencies(result: &mut HashSet<usize>);
// Provided methods
fn name() -> &'static str { ... }
fn is_derived() -> bool { ... }
fn is_required() -> bool { ... }
fn hash_property_value(value: &Self::CanonicalValue) -> u128 { ... }
fn type_id() -> TypeId { ... }
fn index_id() -> usize { ... }
fn non_derived_dependencies() -> Vec<usize> { ... }
fn dependents() -> &'static [usize] { ... }
}Expand description
All properties must implement this trait using one of the define_property macros.
Required Associated Types§
Sourcetype CanonicalValue: AnyProperty
type CanonicalValue: AnyProperty
Some properties might store a transformed version of the value in the index. This is the
type of the transformed value. For simple properties this will be the same as Self.
Required Methods§
Sourcefn initialization_kind() -> PropertyInitializationKind
fn initialization_kind() -> PropertyInitializationKind
The kind of initialization this property has.
Sourcefn compute_derived(context: &Context, entity_id: EntityId<E>) -> Self
fn compute_derived(context: &Context, entity_id: EntityId<E>) -> Self
Compute the value of the property, possibly by accessing the context and using the entity’s ID.
Sourcefn default_const() -> Self
fn default_const() -> Self
Return the default initial constant value.
Sourcefn make_canonical(self) -> Self::CanonicalValue
fn make_canonical(self) -> Self::CanonicalValue
This transforms a Self into a Self::CanonicalValue, e.g., for storage in an index.
For simple properties, this is the identity function.
Sourcefn make_uncanonical(value: Self::CanonicalValue) -> Self
fn make_uncanonical(value: Self::CanonicalValue) -> Self
The inverse transform of make_canonical. For simple properties, this is the identity function.
Sourcefn get_display(&self) -> String
fn get_display(&self) -> String
Returns a string representation of the property value, e.g. for writing to a CSV file.
Sourcefn collect_non_derived_dependencies(result: &mut HashSet<usize>)
fn collect_non_derived_dependencies(result: &mut HashSet<usize>)
An auxiliary helper for non_derived_dependencies above.
Provided Methods§
fn name() -> &'static str
fn is_derived() -> bool
fn is_required() -> bool
Sourcefn hash_property_value(value: &Self::CanonicalValue) -> u128
fn hash_property_value(value: &Self::CanonicalValue) -> u128
For cases when the property’s hash needs to be computed in a special way.
Sourcefn type_id() -> TypeId
fn type_id() -> TypeId
Overridden by multi-properties, which use the TypeId of the ordered tuple so that tuples
with the same component types in a different order will have the same type ID.
Sourcefn index_id() -> usize
fn index_id() -> usize
For properties that use the index of some other property, e.g. multi-properties, this method gives the ID of the property index to use.
Note that this is independent of whether or not the property actually is being indexed,
which is a property of the Context instance, not of the Property<E> type itself.
Sourcefn non_derived_dependencies() -> Vec<usize>
fn non_derived_dependencies() -> Vec<usize>
Returns a vector of transitive non-derived dependencies. If the property is not derived, the
Vec will be empty. The dependencies are represented by their Property<E>::index() value.
This function is only used to construct the static dependency graph
within property ctors, after which time the dependents of a property
are accessible through Property<E>::dependents() as a &'static [usize].
Sourcefn dependents() -> &'static [usize]
fn dependents() -> &'static [usize]
Get a list of derived properties that depend on this property. The properties are
represented by their Property::index(). The list is pre-computed in ctors.
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.