pub struct Entity {
pub name: String,
pub schema: VbrSchemaDefinition,
pub table_name: String,
pub state_machine: Option<StateMachine>,
}Expand description
Entity definition
Fields§
§name: StringEntity name
schema: VbrSchemaDefinitionSchema definition
table_name: StringTable name (derived from entity name)
state_machine: Option<StateMachine>Optional state machine for this entity
If set, the entity can participate in state machine transitions. The state machine defines valid state transitions and lifecycle management.
Implementations§
Source§impl Entity
impl Entity
Sourcepub fn new(name: String, schema: VbrSchemaDefinition) -> Self
pub fn new(name: String, schema: VbrSchemaDefinition) -> Self
Create a new entity
Sourcepub fn with_state_machine(
name: String,
schema: VbrSchemaDefinition,
state_machine: StateMachine,
) -> Self
pub fn with_state_machine( name: String, schema: VbrSchemaDefinition, state_machine: StateMachine, ) -> Self
Create a new entity with a state machine
Sourcepub fn set_state_machine(&mut self, state_machine: StateMachine)
pub fn set_state_machine(&mut self, state_machine: StateMachine)
Set the state machine for this entity
Sourcepub fn state_machine(&self) -> Option<&StateMachine>
pub fn state_machine(&self) -> Option<&StateMachine>
Get the state machine for this entity
Sourcepub fn has_state_machine(&self) -> bool
pub fn has_state_machine(&self) -> bool
Check if this entity has a state machine
Sourcepub async fn apply_state_transition(
&self,
database: &dyn VirtualDatabase,
record_id: &str,
new_state: &str,
state_field_name: Option<&str>,
) -> Result<()>
pub async fn apply_state_transition( &self, database: &dyn VirtualDatabase, record_id: &str, new_state: &str, state_field_name: Option<&str>, ) -> Result<()>
Apply a state transition to an entity record
Updates the entity’s state field in the database based on the state machine transition. The state field name is typically derived from the state machine’s resource_type (e.g., “status” for “Order” resource type).
This method should be called after validating that the transition is allowed by the state machine.
Sourcepub async fn get_current_state(
&self,
database: &dyn VirtualDatabase,
record_id: &str,
state_field_name: Option<&str>,
) -> Result<Option<String>>
pub async fn get_current_state( &self, database: &dyn VirtualDatabase, record_id: &str, state_field_name: Option<&str>, ) -> Result<Option<String>>
Get the current state of an entity record
Reads the state field from the database for a specific record.
Sourcepub async fn can_transition(
&self,
database: &dyn VirtualDatabase,
record_id: &str,
to_state: &str,
state_field_name: Option<&str>,
) -> Result<bool>
pub async fn can_transition( &self, database: &dyn VirtualDatabase, record_id: &str, to_state: &str, state_field_name: Option<&str>, ) -> Result<bool>
Check if a state transition is allowed for an entity record
Validates that the transition from the current state to the new state is allowed by the entity’s state machine.
Sourcepub fn table_name(&self) -> &str
pub fn table_name(&self) -> &str
Get the table name
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Entity
impl RefUnwindSafe for Entity
impl Send for Entity
impl Sync for Entity
impl Unpin for Entity
impl UnsafeUnpin for Entity
impl UnwindSafe for Entity
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more