Enum entity::EdgeValue[][src]

pub enum EdgeValue {
    MaybeOne(Option<Id>),
    One(Id),
    Many(Vec<Id>),
}

Represents the value of an edge, which is some collection of ent ids

Variants

MaybeOne(Option<Id>)

Edge can potentially have one outward connection

One(Id)

Edge can have exactly one outward connection

Many(Vec<Id>)

Edge can have many outward connections

Implementations

impl EdgeValue[src]

pub fn to_ids(&self) -> Vec<Id>[src]

Produces all ids of ents referenced by this edge’s value

Examples

For an optional edge, this can produce a vec of size 0 or 1:

use entity::EdgeValue;

let v = EdgeValue::MaybeOne(None);
assert!(v.to_ids().is_empty());

let v = EdgeValue::MaybeOne(Some(999));
assert_eq!(v.to_ids(), vec![999]);

For a guaranteed edge of 1, this will always produce a vec of size 1:

use entity::EdgeValue;

let v = EdgeValue::One(999);
assert_eq!(v.to_ids(), vec![999]);

For an edge of many ids, this will produce a vec of equal size:

use entity::EdgeValue;

let v = EdgeValue::Many(vec![1, 2, 3, 4]);
assert_eq!(v.to_ids(), vec![1, 2, 3, 4]);

pub fn to_type(&self) -> EdgeValueType[src]

Converts the value to its associated type

Examples

use entity::{EdgeValue, EdgeValueType};

let v = EdgeValue::MaybeOne(None);
assert_eq!(v.to_type(), EdgeValueType::MaybeOne);

let v = EdgeValue::One(999);
assert_eq!(v.to_type(), EdgeValueType::One);

let v = EdgeValue::Many(vec![1, 2, 3]);
assert_eq!(v.to_type(), EdgeValueType::Many);

pub fn add_ids(
    &mut self,
    into_ids: impl IntoIterator<Item = Id>
) -> Result<(), EdgeValueMutationError>
[src]

Adds the provided ids to the edge value, failing if the ids would exceed the maximum allowed by the edge with current ids included

Examples

If edge is an optional, single value, this will fail if the edge already has a value or is provided more than one id. Otherwise, it will succeed.

use entity::EdgeValue;

let mut v = EdgeValue::MaybeOne(Some(1));
assert!(v.add_ids(vec![2]).is_err());
assert!(v.add_ids(vec![]).is_ok());
assert_eq!(v, EdgeValue::MaybeOne(Some(1)));

let mut v = EdgeValue::MaybeOne(None);
assert!(v.add_ids(vec![2, 3]).is_err());
assert_eq!(v, EdgeValue::MaybeOne(None));

let mut v = EdgeValue::MaybeOne(None);
assert!(v.add_ids(vec![]).is_ok());
assert_eq!(v, EdgeValue::MaybeOne(None));

let mut v = EdgeValue::MaybeOne(None);
assert!(v.add_ids(vec![1]).is_ok());
assert_eq!(v, EdgeValue::MaybeOne(Some(1)));

If an edge is exactly one value, this will fail unless an empty list of ids is given as we cannot add any more edge ids.

use entity::EdgeValue;

let mut v = EdgeValue::One(999);
assert!(v.add_ids(vec![1]).is_err());
assert_eq!(v, EdgeValue::One(999));

let mut v = EdgeValue::One(999);
assert!(v.add_ids(vec![]).is_ok());
assert_eq!(v, EdgeValue::One(999));

If an edge can have many ids, this will succeed and append those ids to the end of the list.

use entity::EdgeValue;

let mut v = EdgeValue::Many(vec![]);
assert!(v.add_ids(vec![1, 2, 3]).is_ok());
assert_eq!(v, EdgeValue::Many(vec![1, 2, 3]));

let mut v = EdgeValue::Many(vec![1, 2, 3]);
assert!(v.add_ids(vec![4, 5, 6]).is_ok());
assert_eq!(v, EdgeValue::Many(vec![1, 2, 3, 4, 5, 6]));

pub fn remove_ids(
    &mut self,
    into_ids: impl IntoIterator<Item = Id>
) -> Result<(), EdgeValueMutationError>
[src]

Removes the provided ids from the edge value, failing if the ids would exceed the minimum allowed by the edge with current ids possibly removed

Examples

If edge is an optional, single value, this will never fail as this can either result in the value retaining its id or becoming none.

use entity::EdgeValue;

let mut v = EdgeValue::MaybeOne(Some(1));
assert!(v.remove_ids(vec![2, 3]).is_ok());
assert_eq!(v, EdgeValue::MaybeOne(Some(1)));

let mut v = EdgeValue::MaybeOne(Some(1));
assert!(v.remove_ids(vec![1, 2, 3]).is_ok());
assert_eq!(v, EdgeValue::MaybeOne(None));

let mut v = EdgeValue::MaybeOne(None);
assert!(v.remove_ids(vec![2, 3]).is_ok());
assert_eq!(v, EdgeValue::MaybeOne(None));

let mut v = EdgeValue::MaybeOne(None);
assert!(v.remove_ids(vec![]).is_ok());
assert_eq!(v, EdgeValue::MaybeOne(None));

If an edge is exactly one value, this will fail if it would cause the value to lose its id.

use entity::EdgeValue;

let mut v = EdgeValue::One(999);
assert!(v.remove_ids(vec![999]).is_err());
assert_eq!(v, EdgeValue::One(999));

let mut v = EdgeValue::One(999);
assert!(v.remove_ids(vec![1, 2, 3]).is_ok());
assert_eq!(v, EdgeValue::One(999));

let mut v = EdgeValue::One(999);
assert!(v.remove_ids(vec![]).is_ok());
assert_eq!(v, EdgeValue::One(999));

If an edge can have many ids, this will succeed and remove all ids found within the value.

use entity::EdgeValue;

let mut v = EdgeValue::Many(vec![]);
assert!(v.remove_ids(vec![1, 2, 3]).is_ok());
assert_eq!(v, EdgeValue::Many(vec![]));

let mut v = EdgeValue::Many(vec![1, 2, 3]);
assert!(v.remove_ids(vec![4, 5, 6]).is_ok());
assert_eq!(v, EdgeValue::Many(vec![1, 2, 3]));

let mut v = EdgeValue::Many(vec![1, 2, 3]);
assert!(v.remove_ids(vec![1, 3]).is_ok());
assert_eq!(v, EdgeValue::Many(vec![2]));

Trait Implementations

impl Clone for EdgeValue[src]

impl Debug for EdgeValue[src]

impl Eq for EdgeValue[src]

impl<'_enum> From<&'_enum EdgeValue> for EdgeValueType[src]

impl From<BTreeSet<usize>> for EdgeValue[src]

impl From<BinaryHeap<usize>> for EdgeValue[src]

impl From<EdgeValue> for EdgeValueType[src]

impl From<HashSet<usize, RandomState>> for EdgeValue[src]

impl From<LinkedList<usize>> for EdgeValue[src]

impl From<Option<usize>> for EdgeValue[src]

impl From<Vec<usize, Global>> for EdgeValue[src]

impl From<VecDeque<usize>> for EdgeValue[src]

impl From<usize> for EdgeValue[src]

impl PartialEq<EdgeValue> for EdgeValue[src]

impl StructuralEq for EdgeValue[src]

impl StructuralPartialEq for EdgeValue[src]

impl TryFrom<EdgeValue> for Id[src]

type Error = &'static str

The type returned in the event of a conversion error.

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> DynClone for T where
    T: Clone
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.