pub trait Property<E: Entity>:
Copy
+ Debug
+ PartialEq
+ 'static {
type QueryParts<'a>: AsRef<[&'a dyn Any]>
where Self: 'a;
const NAME: &'static str;
Show 14 methods
// Required methods
fn initialization_kind() -> PropertyInitializationKind;
fn compute_derived(context: &Context, entity_id: EntityId<E>) -> Self;
fn default_const() -> Self;
fn get_display(&self) -> String;
fn query_parts_for_value(value: &Self) -> Self::QueryParts<'_>;
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 value_from_query_parts(parts: &[&dyn Any]) -> Option<Self> { ... }
fn type_id() -> TypeId { ... }
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.
Property values must be copyable and comparable for equality so storage and unindexed
query scans can operate on them. Indexed properties must additionally implement
IndexableProperty.
Required Associated Constants§
Required Associated Types§
Sourcetype QueryParts<'a>: AsRef<[&'a dyn Any]>
where
Self: 'a
type QueryParts<'a>: AsRef<[&'a dyn Any]> where Self: 'a
Allocation-free representation of the query parts contributed by a property value.
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 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 query_parts_for_value(value: &Self) -> Self::QueryParts<'_>
fn query_parts_for_value(value: &Self) -> Self::QueryParts<'_>
Expose the query parts for a concrete property value without allocating.
Ordinary properties contribute a single value. Multi-properties override this so singleton queries over a multi-property can still be matched against the representative multi-property for the equivalent component set.
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 value_from_query_parts(parts: &[&dyn Any]) -> Option<Self>
fn value_from_query_parts(parts: &[&dyn Any]) -> Option<Self>
Reconstruct the property value used for indexed lookup.
Ordinary properties expect a single query part containing Self. Multi-properties override
this to rebuild their declared tuple value directly from already-sorted type-erased query
parts.
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>::id() 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::id(). 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.