Property

Trait Property 

Source
pub trait Property<E: Entity>: AnyProperty {
    type CanonicalValue: AnyProperty;
    type QueryParts<'a>: AsRef<[&'a dyn Any]>
       where Self: 'a;

    const NAME: &'static str;
Show 17 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 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 canonical_from_sorted_query_parts( parts: &[&dyn Any], ) -> Option<Self::CanonicalValue> { ... } 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.

Property values and canonical values must satisfy AnyProperty so they can participate in property indexes.

Required Associated Constants§

Source

const NAME: &'static str

Source-level name, set by the macros to stringify!($property). Used by define_multi_property! to reject type aliases (see issue #843).

Required Associated Types§

Source

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.

Source

type QueryParts<'a>: AsRef<[&'a dyn Any]> where Self: 'a

Allocation-free representation of the query parts contributed by a property value.

Required Methods§

Source

fn initialization_kind() -> PropertyInitializationKind

The kind of initialization this property has.

Source

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.

Source

fn default_const() -> Self

Return the default initial constant value.

Source

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.

Source

fn make_uncanonical(value: Self::CanonicalValue) -> Self

The inverse transform of make_canonical. For simple properties, this is the identity function.

Source

fn get_display(&self) -> String

Returns a string representation of the property value, e.g. for writing to a CSV file.

Source

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 a shared equivalent index.

Source

fn id() -> usize

For implementing the registry pattern

Source

fn collect_non_derived_dependencies(result: &mut HashSet<usize>)

An auxiliary helper for non_derived_dependencies above.

Provided Methods§

Source

fn name() -> &'static str

Source

fn is_derived() -> bool

Source

fn is_required() -> bool

Source

fn canonical_from_sorted_query_parts( parts: &[&dyn Any], ) -> Option<Self::CanonicalValue>

Reconstruct the canonical query value used for indexed lookup.

Ordinary properties expect a single query part containing Self and canonicalize that value. Multi-properties override this to rebuild their canonical tuple value directly from the already-sorted type-erased query parts.

Source

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.

Source

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.

Source

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].

Source

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.

Implementors§