UntypedEnt

Struct UntypedEnt 

Source
pub struct UntypedEnt { /* private fields */ }
Expand description

Represents a general-purpose ent that is shapeless (no hard type) and maintains fields and edges using internal maps. This ent can optionally be connected to a database and supports additional functionality like loading ents from edges when connected.

Implementations§

Source§

impl UntypedEnt

Source

pub fn new( id: Id, fields: HashMap<String, Field>, edges: HashMap<String, Edge>, ) -> Self

Creates a new ent using the given id, field map, and edge map

Source

pub fn empty_with_id(id: Id) -> Self

Creates an empty ent with the provided id

Source

pub fn from_collections<FI: IntoIterator<Item = Field>, EI: IntoIterator<Item = Edge>>( id: Id, field_collection: FI, edge_collection: EI, ) -> Self

Creates a map ent with the provided id, fields from the given collection, and edges from the other given collection

Trait Implementations§

Source§

impl Clone for UntypedEnt

Source§

fn clone(&self) -> UntypedEnt

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for UntypedEnt

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for UntypedEnt

Source§

fn default() -> Self

Creates an untyped ent with the ephemeral id

Source§

impl Display for UntypedEnt

Source§

fn fmt(&self, _derive_more_display_formatter: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Ent for UntypedEnt

Source§

fn id(&self) -> Id

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);
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

§Examples
use entity::{UntypedEnt, Ent};

let ent = UntypedEnt::default();
assert_eq!(ent.r#type(), "entity::ent::UntypedEnt");
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 local, internal timestamp of this ent instance

Source§

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

Represents the definitions of fields contained within the ent instance

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

let fields = vec![
    Field::new("field1", 123u8),
    Field::new("field2", Value::from("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,
)));
Source§

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

Represents the names of fields contained within the ent instance

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

let fields = vec![
    Field::new("field1", 123u8),
    Field::new("field2", Value::from("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")));
Source§

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

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", Value::from("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);
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

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

let fields = vec![
    Field::new("field1", 123u8),
    Field::new("field2", Value::from("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)));
Source§

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

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,
)));
Source§

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

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")));
Source§

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

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);
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

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

fn connect(&mut self, database: WeakDatabaseRc)

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

Source§

fn disconnect(&mut self)

Disconnects ent from the given database. All future database-related 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 the locally-cached, computed fields of 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

Source§

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

Returns definition for the field with specified name
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_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
Source§

impl EntType for UntypedEnt

Source§

fn type_data() -> EntTypeData

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

§Examples
use entity::{UntypedEnt, EntType, EntTypeData};

assert!(matches!(
    UntypedEnt::type_data(),
    EntTypeData::Concrete { ty: "entity::ent::UntypedEnt" },
));
Source§

fn type_str() -> &'static str

Returns a static str that represents the unique type for an ent
Source§

fn is_concrete_type() -> bool

Indicates whether the ent represents a concrete type (like a struct) or a wrapper around one of many types (like an enum)
Source§

fn wrapped_tys() -> Option<HashSet<&'static str>>

Represents the types that this ent wraps if it is not a concrete ent
Source§

impl PartialEq for UntypedEnt

Source§

fn eq(&self, other: &Self) -> bool

Untyped Ents are considered equal if their ids, fields, edges, creation date, and updated date are all equal

1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Eq for UntypedEnt

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> AsAny for T
where T: 'static,

Source§

fn as_any(&self) -> &(dyn Any + 'static)

Converts reference to Any
Source§

fn as_mut_any(&mut self) -> &mut (dyn Any + 'static)

converts mutable reference to Any
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<T> EntExt for T
where T: Ent,

Source§

fn load_edge_typed<E>(&self, name: &str) -> Result<Vec<E>, DatabaseError>
where E: Ent,

Loads ents of a specified type from a named edge
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.