EdgeValue

Enum EdgeValue 

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

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§

Source§

impl EdgeValue

Source

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

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

pub fn to_type(&self) -> EdgeValueType

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

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

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

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

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§

Source§

impl Clone for EdgeValue

Source§

fn clone(&self) -> EdgeValue

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 EdgeValue

Source§

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

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

impl<'_enum> From<&'_enum EdgeValue> for EdgeValueType

Source§

fn from(val: &'_enum EdgeValue) -> EdgeValueType

Converts to this type from the input type.
Source§

impl From<BTreeSet<usize>> for EdgeValue

Source§

fn from(x: BTreeSet<Id>) -> Self

Converts to this type from the input type.
Source§

impl From<BinaryHeap<usize>> for EdgeValue

Source§

fn from(x: BinaryHeap<Id>) -> Self

Converts to this type from the input type.
Source§

impl From<EdgeValue> for EdgeValueType

Source§

fn from(val: EdgeValue) -> EdgeValueType

Converts to this type from the input type.
Source§

impl From<HashSet<usize>> for EdgeValue

Source§

fn from(x: HashSet<Id>) -> Self

Converts to this type from the input type.
Source§

impl From<LinkedList<usize>> for EdgeValue

Source§

fn from(x: LinkedList<Id>) -> Self

Converts to this type from the input type.
Source§

impl From<Option<usize>> for EdgeValue

Source§

fn from(original: Option<Id>) -> EdgeValue

Converts to this type from the input type.
Source§

impl From<Vec<usize>> for EdgeValue

Source§

fn from(original: Vec<Id>) -> EdgeValue

Converts to this type from the input type.
Source§

impl From<VecDeque<usize>> for EdgeValue

Source§

fn from(x: VecDeque<Id>) -> Self

Converts to this type from the input type.
Source§

impl From<usize> for EdgeValue

Source§

fn from(original: Id) -> EdgeValue

Converts to this type from the input type.
Source§

impl PartialEq for EdgeValue

Source§

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

Tests for self and other values to be equal, and is used by ==.
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 TryFrom<EdgeValue> for BTreeSet<Id>

Source§

type Error = &'static str

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

fn try_from(x: EdgeValue) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<EdgeValue> for BinaryHeap<Id>

Source§

type Error = &'static str

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

fn try_from(x: EdgeValue) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<EdgeValue> for HashSet<Id>

Source§

type Error = &'static str

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

fn try_from(x: EdgeValue) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<EdgeValue> for LinkedList<Id>

Source§

type Error = &'static str

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

fn try_from(x: EdgeValue) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<EdgeValue> for Option<Id>

Source§

type Error = &'static str

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

fn try_from(value: EdgeValue) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<EdgeValue> for Vec<Id>

Source§

type Error = &'static str

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

fn try_from(value: EdgeValue) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<EdgeValue> for VecDeque<Id>

Source§

type Error = &'static str

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

fn try_from(x: EdgeValue) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<EdgeValue> for Id

Source§

type Error = &'static str

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

fn try_from(value: EdgeValue) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl Eq for EdgeValue

Source§

impl StructuralPartialEq for EdgeValue

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> 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, 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.