[−][src]Enum entity::EdgeValue
Represents the value of an edge, which is some collection of ent ids
Variants
Edge can potentially have one outward connection
One(Id)
Edge can have exactly one outward connection
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]
&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]));
pub fn remove_ids(
&mut self,
into_ids: impl IntoIterator<Item = Id>
) -> Result<(), EdgeValueMutationError>
[src]
&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
impl Clone for EdgeValue
[src]
impl Debug for EdgeValue
[src]
impl Eq for EdgeValue
[src]
impl<'_enum> From<&'_enum EdgeValue> for EdgeValueType
[src]
pub fn from(val: &'_enum EdgeValue) -> EdgeValueType
[src]
impl From<EdgeValue> for EdgeValueType
[src]
pub fn from(val: EdgeValue) -> EdgeValueType
[src]
impl From<Option<usize>> for EdgeValue
[src]
impl From<Vec<usize, Global>> 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]
Auto Trait Implementations
impl RefUnwindSafe for EdgeValue
[src]
impl Send for EdgeValue
[src]
impl Sync for EdgeValue
[src]
impl Unpin for EdgeValue
[src]
impl UnwindSafe for EdgeValue
[src]
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> DynClone for T where
T: Clone,
[src]
T: Clone,
pub fn __clone_box(&self, Private) -> *mut ()
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,