pub trait ValueLookupObjectSpace<U>: ObjectSpace {
// Required methods
fn try_read_by_value<T>(&self, field: &str, key: &U) -> Option<T>
where for<'de> T: Serialize + Deserialize<'de> + 'static;
fn read_all_by_value<'a, T>(
&'a self,
field: &str,
key: &U,
) -> Box<dyn Iterator<Item = T> + 'a>
where for<'de> T: Deserialize<'de> + 'static;
fn read_by_value<T>(&self, field: &str, key: &U) -> T
where for<'de> T: Serialize + Deserialize<'de> + 'static;
fn try_take_by_value<T>(&self, field: &str, key: &U) -> Option<T>
where for<'de> T: Serialize + Deserialize<'de> + 'static;
fn take_all_by_value<'a, T>(
&'a self,
field: &str,
key: &U,
) -> Box<dyn Iterator<Item = T> + 'a>
where for<'de> T: Deserialize<'de> + 'static;
fn take_by_value<T>(&self, field: &str, key: &U) -> T
where for<'de> T: Serialize + Deserialize<'de> + 'static;
}
Expand description
An extension of ObjectSpace
supporting retrieving structs by value of a field.
Given a type T
with a field (might be nested) of type U
,
a path to a field of type U
and a value of type U
,
an ValueLookupObjectSpace<U>
could retrieve structs of type T
whose value of the specified field equals to the specified value.
§Example
let space = TreeObjectSpace::new();
space.write::<i64>(3);
space.write::<i64>(5);
assert_eq!(space.try_read_by_value::<i64>("", &3), Some(3));
assert_eq!(space.try_read_by_value::<i64>("", &2), None);
Required Methods§
Sourcefn try_read_by_value<T>(&self, field: &str, key: &U) -> Option<T>where
for<'de> T: Serialize + Deserialize<'de> + 'static,
fn try_read_by_value<T>(&self, field: &str, key: &U) -> Option<T>where
for<'de> T: Serialize + Deserialize<'de> + 'static,
Given a path to an element of the struct and a possible value, return a copy of a struct whose specified element of the specified value. The operation is non-blocking and will returns None if no struct satisfies condition.
§Example
let space = TreeObjectSpace::new();
space.write::<i64>(3);
space.write::<i64>(5);
assert_eq!(space.try_read_by_value::<i64>("", &3), Some(3));
assert_eq!(space.try_read_by_value::<i64>("", &2), None);
Sourcefn read_all_by_value<'a, T>(
&'a self,
field: &str,
key: &U,
) -> Box<dyn Iterator<Item = T> + 'a>where
for<'de> T: Deserialize<'de> + 'static,
fn read_all_by_value<'a, T>(
&'a self,
field: &str,
key: &U,
) -> Box<dyn Iterator<Item = T> + 'a>where
for<'de> T: Deserialize<'de> + 'static,
Given a path to an element of the struct and a possible value, return copies of all structs whose specified element of the specified value.
§Example
let space = TreeObjectSpace::new();
space.write::<i64>(3);
space.write::<i64>(5);
assert_eq!(space.read_all_by_value::<i64>("", &3).count(), 1);
assert_eq!(space.read_all_by_value::<i64>("", &2).count(), 0);
Sourcefn read_by_value<T>(&self, field: &str, key: &U) -> Twhere
for<'de> T: Serialize + Deserialize<'de> + 'static,
fn read_by_value<T>(&self, field: &str, key: &U) -> Twhere
for<'de> T: Serialize + Deserialize<'de> + 'static,
Given a path to an element of the struct and a possible value, return a copy of a struct whose specified element of the specified value. The operation is blocks until an element satisfies the condition is found.
§Example
let space = TreeObjectSpace::new();
space.write::<i64>(3);
space.write::<i64>(5);
assert_eq!(space.read_by_value::<i64>("", &3), 3);
Sourcefn try_take_by_value<T>(&self, field: &str, key: &U) -> Option<T>where
for<'de> T: Serialize + Deserialize<'de> + 'static,
fn try_take_by_value<T>(&self, field: &str, key: &U) -> Option<T>where
for<'de> T: Serialize + Deserialize<'de> + 'static,
Given a path to an element of the struct and a possible value, remove and return a struct whose specified element of the specified value. The operation is non-blocking and will returns None if no struct satisfies condition.
§Example
let space = TreeObjectSpace::new();
space.write::<i64>(3);
space.write::<i64>(5);
assert_eq!(space.try_take_by_value::<i64>("", &3), Some(3));
assert_eq!(space.try_take_by_value::<i64>("", &3), None);
assert_eq!(space.try_take_by_value::<i64>("", &4), None);
Sourcefn take_all_by_value<'a, T>(
&'a self,
field: &str,
key: &U,
) -> Box<dyn Iterator<Item = T> + 'a>where
for<'de> T: Deserialize<'de> + 'static,
fn take_all_by_value<'a, T>(
&'a self,
field: &str,
key: &U,
) -> Box<dyn Iterator<Item = T> + 'a>where
for<'de> T: Deserialize<'de> + 'static,
Given a path to an element of the struct and a possible value, remove and return all structs whose specified element of the specified value.
§Example
let space = TreeObjectSpace::new();
space.write::<i64>(3);
space.write::<i64>(5);
assert_eq!(space.take_all_by_value::<i64>("", &3).count(), 1);
assert_eq!(space.take_all_by_value::<i64>("", &4).count(), 0);
Sourcefn take_by_value<T>(&self, field: &str, key: &U) -> Twhere
for<'de> T: Serialize + Deserialize<'de> + 'static,
fn take_by_value<T>(&self, field: &str, key: &U) -> Twhere
for<'de> T: Serialize + Deserialize<'de> + 'static,
Given a path to an element of the struct and a possible value, remove and return a struct whose specified element of the specified value. The operation is blocks until an element satisfies the condition is found.
§Example
let space = TreeObjectSpace::new();
space.write::<i64>(3);
space.write::<i64>(5);
assert_eq!(space.take_by_value::<i64>("", &3), 3);
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.