Ent

Trait Ent 

Source
pub trait Ent:
    AsAny
    + DynClone
    + Send
    + Sync {
Show 28 methods // Required methods fn id(&self) -> Id; fn set_id(&mut self, id: Id); fn type(&self) -> &str; fn created(&self) -> u64; fn last_updated(&self) -> u64; fn mark_updated(&mut self) -> Result<(), EntMutationError>; fn field_definitions(&self) -> Vec<FieldDefinition>; fn field(&self, name: &str) -> Option<Value>; fn update_field( &mut self, name: &str, value: Value, ) -> Result<Value, EntMutationError>; fn edge_definitions(&self) -> Vec<EdgeDefinition>; fn edge(&self, name: &str) -> Option<EdgeValue>; fn update_edge( &mut self, name: &str, value: EdgeValue, ) -> Result<EdgeValue, EntMutationError>; fn connect(&mut self, database: WeakDatabaseRc); fn disconnect(&mut self); fn is_connected(&self) -> bool; fn load_edge(&self, name: &str) -> DatabaseResult<Vec<Box<dyn Ent>>>; fn clear_cache(&mut self); fn refresh(&mut self) -> DatabaseResult<()>; fn commit(&mut self) -> DatabaseResult<()>; fn remove(&self) -> DatabaseResult<bool>; // Provided methods fn field_definition(&self, name: &str) -> Option<FieldDefinition> { ... } fn field_names(&self) -> Vec<String> { ... } fn field_type(&self, name: &str) -> Option<ValueType> { ... } fn fields(&self) -> Vec<Field> { ... } fn edge_definition(&self, name: &str) -> Option<EdgeDefinition> { ... } fn edge_names(&self) -> Vec<String> { ... } fn edge_type(&self, name: &str) -> Option<EdgeValueType> { ... } fn edges(&self) -> Vec<Edge> { ... }
}
Expand description

Represents the interface for a generic entity whose fields and edges can be accessed by str name regardless of compile-time characteristics

Based on https://www.usenix.org/system/files/conference/atc13/atc13-bronson.pdf

Required Methods§

Source

fn id(&self) -> Id

Represents the unique id associated with each entity instance

Source

fn set_id(&mut self, id: Id)

Updates the id of this ent, useful for databases that want to adjust the id or when you want to produce a clone of the ent in a database by resetting its id to ephemeral prior to storing it

Source

fn type(&self) -> &str

Represents a unique type associated with the entity, used for lookups, indexing by type, and conversions

Source

fn created(&self) -> u64

Represents the time when the instance of the ent was created as the milliseconds since epoch (1970-01-01 00:00:00 UTC)

Source

fn last_updated(&self) -> u64

Represents the time when the instance of the ent was last updated as the milliseconds since epoch (1970-01-01 00:00:00 UTC)

Source

fn mark_updated(&mut self) -> Result<(), EntMutationError>

Updates the time when the instance of the ent was last updated to the current time in milliseconds since epoch (1970-01-01 00:00:00 UTC)

Source

fn field_definitions(&self) -> Vec<FieldDefinition>

Returns a list of definitions for fields contained by the ent

Source

fn field(&self, name: &str) -> Option<Value>

Returns a copy of the value of the field with the specified name

Source

fn update_field( &mut self, name: &str, value: Value, ) -> Result<Value, EntMutationError>

Updates the local value of a field with the specified name, returning the old field value if updated. This will also update the last updated time for the ent.

Source

fn edge_definitions(&self) -> Vec<EdgeDefinition>

Returns a list of definitions for edges contained by the ent

Source

fn edge(&self, name: &str) -> Option<EdgeValue>

Returns a copy of the value of the edge with the specified name

Source

fn update_edge( &mut self, name: &str, value: EdgeValue, ) -> Result<EdgeValue, EntMutationError>

Updates the local value of an edge with the specified name, returning the old edge value if updated. This will also update the last updated time for the ent.

Source

fn connect(&mut self, database: WeakDatabaseRc)

Connects ent to the given database so all future database-related operations will be performed against this database

Source

fn disconnect(&mut self)

Disconnects ent from any associated database. All future database operations will fail with a disconnected database error

Source

fn is_connected(&self) -> bool

Returns true if ent is currently connected to a database

Source

fn load_edge(&self, name: &str) -> DatabaseResult<Vec<Box<dyn Ent>>>

Loads the ents connected by the edge with the given name

Requires ent to be connected to a database

Source

fn clear_cache(&mut self)

Clears out any locally-cached data for the ent

Source

fn refresh(&mut self) -> DatabaseResult<()>

Refreshes ent by checking database for latest version and returning it

Requires ent to be connected to a database

Source

fn commit(&mut self) -> DatabaseResult<()>

Saves the ent to the database, updating this local instance’s id if the database has reported a new id

Requires ent to be connected to a database

Source

fn remove(&self) -> DatabaseResult<bool>

Removes self from database, returning true if successful

Requires ent to be connected to a database

Provided Methods§

Source

fn field_definition(&self, name: &str) -> Option<FieldDefinition>

Returns definition for the field with specified name

Source

fn field_names(&self) -> Vec<String>

Returns a list of names of fields contained by the ent

Source

fn field_type(&self, name: &str) -> Option<ValueType>

Returns a copy of the type of the field with the specified name

Source

fn fields(&self) -> Vec<Field>

Returns a copy of all fields contained by the ent and their associated values

Source

fn edge_definition(&self, name: &str) -> Option<EdgeDefinition>

Returns definition for the edge with specified name

Source

fn edge_names(&self) -> Vec<String>

Returns a list of names of edges contained by the ent

Source

fn edge_type(&self, name: &str) -> Option<EdgeValueType>

Returns a copy of the type of the edge with the specified name

Source

fn edges(&self) -> Vec<Edge>

Returns a copy of all edges contained by the ent and their associated values

Implementations§

Source§

impl dyn Ent

Implementation for a generic trait object of Ent that provides methods to downcast into a concrete type

Source

pub fn as_ent<E: Ent>(&self) -> Option<&E>

Attempts to convert this dynamic Ent ref into a concrete Ent ref by downcasting

Source

pub fn as_mut_ent<E: Ent>(&mut self) -> Option<&mut E>

Attempts to convert this dynamic Ent mutable ref into a concrete Ent mutable ref by downcasting

Source

pub fn to_ent<E: Ent>(&self) -> Option<E>

Attempts to convert this dynamic Ent ref into a concrete ent by downcasting and then cloning

Implementors§