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
impl EdgeValue
Sourcepub fn to_ids(&self) -> Vec<Id> ⓘ
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]);Sourcepub fn to_type(&self) -> EdgeValueType
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);Sourcepub fn add_ids(
&mut self,
into_ids: impl IntoIterator<Item = Id>,
) -> Result<(), EdgeValueMutationError>
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]));Sourcepub fn remove_ids(
&mut self,
into_ids: impl IntoIterator<Item = Id>,
) -> Result<(), EdgeValueMutationError>
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]));