[][src]Trait entity::Ent

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

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

pub fn id(&self) -> Id[src]

Represents the unique id associated with each entity instance

pub fn set_id(&mut self, id: Id)[src]

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

pub fn type(&self) -> &str[src]

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

pub fn created(&self) -> u64[src]

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

pub fn last_updated(&self) -> u64[src]

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

pub fn mark_updated(&mut self) -> Result<(), EntMutationError>[src]

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)

pub fn field_definitions(&self) -> Vec<FieldDefinition>[src]

Returns a list of definitions for fields contained by the ent

pub fn field(&self, name: &str) -> Option<Value>[src]

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

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

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.

pub fn edge_definitions(&self) -> Vec<EdgeDefinition>[src]

Returns a list of definitions for edges contained by the ent

pub fn edge(&self, name: &str) -> Option<EdgeValue>[src]

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

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

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.

pub fn connect(&mut self, database: WeakDatabaseRc)[src]

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

pub fn disconnect(&mut self)[src]

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

pub fn is_connected(&self) -> bool[src]

Returns true if ent is currently connected to a database

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

Loads the ents connected by the edge with the given name

Requires ent to be connected to a database

pub fn refresh(&mut self) -> DatabaseResult<()>[src]

Refreshes ent by checking database for latest version and returning it

Requires ent to be connected to a database

pub fn commit(&mut self) -> DatabaseResult<()>[src]

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

pub fn remove(&self) -> DatabaseResult<bool>[src]

Removes self from database, returning true if successful

Requires ent to be connected to a database

Loading content...

Provided methods

pub fn field_names(&self) -> Vec<String>[src]

Returns a list of names of fields contained by the ent

pub fn fields(&self) -> Vec<Field>[src]

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

pub fn edge_names(&self) -> Vec<String>[src]

Returns a list of names of edges contained by the ent

pub fn edges(&self) -> Vec<Edge>[src]

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

Loading content...

Implementations

impl dyn Ent[src]

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

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

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

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

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

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

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

Implementors

impl Ent for UntypedEnt[src]

pub fn id(&self) -> Id[src]

Represents the unique id associated with each entity instance

Examples

use entity::{Ent, UntypedEnt};

let ent = UntypedEnt::empty_with_id(999);
assert_eq!(ent.id(), 999);

pub fn set_id(&mut self, id: Id)[src]

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

pub fn type(&self) -> &str[src]

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

Examples

use entity::{UntypedEnt, Ent};

let ent = UntypedEnt::default();
assert_eq!(ent.r#type(), "entity::ent::UntypedEnt");

pub fn created(&self) -> u64[src]

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

pub fn last_updated(&self) -> u64[src]

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

pub fn mark_updated(&mut self) -> Result<(), EntMutationError>[src]

Updates the local, internal timestamp of this ent instance

pub fn field_definitions(&self) -> Vec<FieldDefinition>[src]

Represents the definitions of fields contained within the ent instance

Examples

use entity::{Ent, UntypedEnt, Field, FieldDefinition, ValueType};
use std::str::FromStr;

let fields = vec![
    Field::new("field1", 123u8),
    Field::new("field2", "some text"),
];
let ent = UntypedEnt::from_collections(0, fields.iter().cloned(), vec![]);

let defs = ent.field_definitions();
assert_eq!(defs.len(), 2);
assert!(defs.contains(&FieldDefinition::new(
    "field1",
    ValueType::from_str("u8").unwrap(),
)));
assert!(defs.contains(&FieldDefinition::new(
    "field2",
    ValueType::Text,
)));

pub fn field_names(&self) -> Vec<String>[src]

Represents the names of fields contained within the ent instance

Examples

use entity::{Ent, UntypedEnt, Field};

let fields = vec![
    Field::new("field1", 123u8),
    Field::new("field2", "some text"),
];
let ent = UntypedEnt::from_collections(0, fields.iter().cloned(), vec![]);

let names = ent.field_names();
assert_eq!(names.len(), 2);
assert!(names.contains(&String::from("field1")));
assert!(names.contains(&String::from("field2")));

pub fn field(&self, name: &str) -> Option<Value>[src]

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

Examples

use entity::{Ent, UntypedEnt, Field, Value};

let fields = vec![
    Field::new("field1", 123u8),
    Field::new("field2", "some text"),
];
let ent = UntypedEnt::from_collections(0, fields.iter().cloned(), vec![]);

assert_eq!(ent.field("field1"), Some(Value::from(123u8)));
assert_eq!(ent.field("unknown"), None);

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

Updates the local value of a field with the specified name, returning the old field value if updated

Examples

use entity::{Ent, UntypedEnt, Field, Value};

let fields = vec![
    Field::new("field1", 123u8),
    Field::new("field2", "some text"),
];
let mut ent = UntypedEnt::from_collections(0, fields.iter().cloned(), vec![]);

ent.update_field("field1", Value::from(5u8)).unwrap();
assert_eq!(ent.field("field1"), Some(Value::from(5u8)));

pub fn edge_definitions(&self) -> Vec<EdgeDefinition>[src]

Represents the definitions of edges contained within the ent instance

Examples

use entity::{Ent, UntypedEnt, Edge, EdgeDefinition, EdgeValueType};
use std::str::FromStr;

let edges = vec![
    Edge::new("edge1", 99),
    Edge::new("edge2", vec![1, 2, 3]),
];
let ent = UntypedEnt::from_collections(0, vec![], edges);

let defs = ent.edge_definitions();
assert_eq!(defs.len(), 2);
assert!(defs.contains(&EdgeDefinition::new(
    "edge1",
    EdgeValueType::One,
)));
assert!(defs.contains(&EdgeDefinition::new(
    "edge2",
    EdgeValueType::Many,
)));

pub fn edge_names(&self) -> Vec<String>[src]

Returns a list of names of edges contained by the ent

Examples

use entity::{Ent, UntypedEnt, Edge};

let edges = vec![
    Edge::new("edge1", 99),
    Edge::new("edge2", vec![1, 2, 3]),
];
let ent = UntypedEnt::from_collections(0, vec![], edges);

let names = ent.edge_names();
assert_eq!(names.len(), 2);
assert!(names.contains(&String::from("edge1")));
assert!(names.contains(&String::from("edge2")));

pub fn edge(&self, name: &str) -> Option<EdgeValue>[src]

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

Examples

use entity::{Ent, UntypedEnt, Edge, EdgeValue};

let edges = vec![
    Edge::new("edge1", 99),
    Edge::new("edge2", vec![1, 2, 3]),
];
let ent = UntypedEnt::from_collections(0,  vec![], edges);

assert_eq!(ent.edge("edge1"), Some(EdgeValue::One(99)));
assert_eq!(ent.edge("edge2"), Some(EdgeValue::Many(vec![1, 2, 3])));
assert_eq!(ent.edge("unknown"), None);

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

Updates the local value of an edge with the specified name, returning the old edge value if updated

Examples

use entity::{Ent, UntypedEnt, Edge, EdgeValue};

let edges = vec![
    Edge::new("edge1", 99),
    Edge::new("edge2", vec![1, 2, 3]),
];
let mut ent = UntypedEnt::from_collections(0,  vec![], edges);

ent.update_edge("edge1", EdgeValue::One(123)).unwrap();
assert_eq!(ent.edge("edge1"), Some(EdgeValue::One(123)));

pub fn connect(&mut self, database: WeakDatabaseRc)[src]

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

pub fn disconnect(&mut self)[src]

Disconnects ent from the given database. All future database-related operations will fail with a disconnected database error

pub fn is_connected(&self) -> bool[src]

Returns true if ent is currently connected to a database

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

Loads the ents connected by the edge with the given name

Requires ent to be connected to a database

pub fn refresh(&mut self) -> DatabaseResult<()>[src]

Refreshes ent by checking database for latest version and returning it

Requires ent to be connected to a database

pub fn commit(&mut self) -> DatabaseResult<()>[src]

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

pub fn remove(&self) -> DatabaseResult<bool>[src]

Removes self from database, returning true if successful

Requires ent to be connected to a database

Loading content...