pub struct EntityDescriptor {
pub type_name: &'static str,
pub type_id: TypeId,
pub solution_field: &'static str,
pub is_collection: bool,
pub variable_descriptors: Vec<VariableDescriptor>,
pub extractor: Option<Box<dyn EntityExtractor>>,
pub id_field: Option<&'static str>,
pub pin_field: Option<&'static str>,
}Expand description
Describes a planning entity type at runtime.
Fields§
§type_name: &'static strName of the entity type.
type_id: TypeIdTypeId of the entity type.
solution_field: &'static strField name in the solution (for entity collections).
is_collection: boolWhether this is a collection of entities.
variable_descriptors: Vec<VariableDescriptor>Variable descriptors for this entity (metadata only).
extractor: Option<Box<dyn EntityExtractor>>Extractor for getting entities from a solution.
id_field: Option<&'static str>The ID field name, if any.
pin_field: Option<&'static str>The pinning field name, if any.
Implementations§
Source§impl EntityDescriptor
impl EntityDescriptor
Sourcepub fn new(
type_name: &'static str,
type_id: TypeId,
solution_field: &'static str,
) -> Self
pub fn new( type_name: &'static str, type_id: TypeId, solution_field: &'static str, ) -> Self
Creates a new EntityDescriptor.
Sourcepub fn with_extractor(self, extractor: Box<dyn EntityExtractor>) -> Self
pub fn with_extractor(self, extractor: Box<dyn EntityExtractor>) -> Self
Sets the entity extractor for this descriptor.
Sourcepub fn with_variable(self, descriptor: VariableDescriptor) -> Self
pub fn with_variable(self, descriptor: VariableDescriptor) -> Self
Adds a variable descriptor (metadata only).
Sourcepub fn with_id_field(self, field: &'static str) -> Self
pub fn with_id_field(self, field: &'static str) -> Self
Sets the ID field.
Sourcepub fn with_pin_field(self, field: &'static str) -> Self
pub fn with_pin_field(self, field: &'static str) -> Self
Sets the pin field.
Sourcepub fn genuine_variable_descriptors(
&self,
) -> impl Iterator<Item = &VariableDescriptor>
pub fn genuine_variable_descriptors( &self, ) -> impl Iterator<Item = &VariableDescriptor>
Returns genuine (non-shadow) variable descriptors.
Sourcepub fn shadow_variable_descriptors(
&self,
) -> impl Iterator<Item = &VariableDescriptor>
pub fn shadow_variable_descriptors( &self, ) -> impl Iterator<Item = &VariableDescriptor>
Returns shadow variable descriptors.
Sourcepub fn find_variable(&self, name: &str) -> Option<&VariableDescriptor>
pub fn find_variable(&self, name: &str) -> Option<&VariableDescriptor>
Finds a variable descriptor by name.
Sourcepub fn has_genuine_variables(&self) -> bool
pub fn has_genuine_variables(&self) -> bool
Returns true if this entity has any genuine variables.
Sourcepub fn has_extractor(&self) -> bool
pub fn has_extractor(&self) -> bool
Returns whether this descriptor has an entity extractor.
Sourcepub fn entity_count(&self, solution: &dyn Any) -> Option<usize>
pub fn entity_count(&self, solution: &dyn Any) -> Option<usize>
Returns the number of entities in the solution.
Returns None if no extractor is set or solution type doesn’t match.
Sourcepub fn get_entity<'a>(
&self,
solution: &'a dyn Any,
index: usize,
) -> Option<&'a dyn Any>
pub fn get_entity<'a>( &self, solution: &'a dyn Any, index: usize, ) -> Option<&'a dyn Any>
Gets a reference to an entity by index.
Returns None if no extractor is set, index is out of bounds,
or solution type doesn’t match.
Sourcepub fn get_entity_mut<'a>(
&self,
solution: &'a mut dyn Any,
index: usize,
) -> Option<&'a mut dyn Any>
pub fn get_entity_mut<'a>( &self, solution: &'a mut dyn Any, index: usize, ) -> Option<&'a mut dyn Any>
Gets a mutable reference to an entity by index.
Returns None if no extractor is set, index is out of bounds,
or solution type doesn’t match.
Sourcepub fn entity_refs(&self, solution: &dyn Any) -> Vec<EntityRef>
pub fn entity_refs(&self, solution: &dyn Any) -> Vec<EntityRef>
Returns references to all entities in the solution.
Returns an empty vector if no extractor is set or solution type doesn’t match.
Sourcepub fn for_each_entity<F>(&self, solution: &dyn Any, f: F) -> Option<()>
pub fn for_each_entity<F>(&self, solution: &dyn Any, f: F) -> Option<()>
Iterates over all entities, applying a function to each.
Returns None if no extractor is set or solution type doesn’t match.
Sourcepub fn for_each_entity_mut<F>(&self, solution: &mut dyn Any, f: F) -> Option<()>
pub fn for_each_entity_mut<F>(&self, solution: &mut dyn Any, f: F) -> Option<()>
Iterates over all entities mutably, applying a function to each.
Note: This requires the solution to be borrowed mutably for each entity access, which means the callback cannot hold references to previous entities.