Skip to main content

Property

Trait Property 

Source
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§

Source

const NAME: &'static str

Source-level name, set by the macros to stringify!($property).

Required Associated Types§

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 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 the representative multi-property for the equivalent component set.

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

Source

fn type_id() -> TypeId

The logical type identity for this property.

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

Source

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.

Implementors§