pub trait RangeLookupObjectSpace<U>: ObjectSpace {
// Required methods
fn try_read_by_range<T, R>(&self, field: &str, range: R) -> Option<T>
where for<'de> T: Serialize + Deserialize<'de> + 'static,
R: RangeBounds<U> + Clone;
fn read_all_by_range<'a, T, R>(
&'a self,
field: &str,
range: R,
) -> Box<dyn Iterator<Item = T> + 'a>
where for<'de> T: Deserialize<'de> + 'static,
R: RangeBounds<U> + Clone;
fn read_by_range<T, R>(&self, field: &str, range: R) -> T
where for<'de> T: Serialize + Deserialize<'de> + 'static,
R: RangeBounds<U> + Clone;
fn try_take_by_range<T, R>(&self, field: &str, range: R) -> Option<T>
where for<'de> T: Serialize + Deserialize<'de> + 'static,
R: RangeBounds<U> + Clone;
fn take_all_by_range<'a, T, R>(
&'a self,
field: &str,
range: R,
) -> Box<dyn Iterator<Item = T> + 'a>
where for<'de> T: Deserialize<'de> + 'static,
R: RangeBounds<U> + Clone;
fn take_by_range<T, R>(&self, field: &str, range: R) -> T
where for<'de> T: Serialize + Deserialize<'de> + 'static,
R: RangeBounds<U> + Clone;
}
Expand description
An extension of ObjectSpace
supporting retrieving structs by range 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 RangeBounds<U>
,
an RangeLookupObjectSpace<U>
could retrieve structs of type T
whose value of the specified field is within the given range.
§Example
let space = TreeObjectSpace::new();
space.write::<i64>(3);
space.write::<i64>(5);
assert_eq!(space.try_read_by_range::<i64, _>("", 2..4), Some(3));
assert_eq!(space.try_read_by_range::<i64, _>("", ..2), None);
Required Methods§
Sourcefn try_read_by_range<T, R>(&self, field: &str, range: R) -> Option<T>
fn try_read_by_range<T, R>(&self, field: &str, range: R) -> Option<T>
Given a path to an element of the struct and a range of possible values, return a copy of a struct whose specified element is within the range. 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_range::<i64, _>("", 2..4), Some(3));
assert_eq!(space.try_read_by_range::<i64, _>("", ..2), None);
Sourcefn read_all_by_range<'a, T, R>(
&'a self,
field: &str,
range: R,
) -> Box<dyn Iterator<Item = T> + 'a>
fn read_all_by_range<'a, T, R>( &'a self, field: &str, range: R, ) -> Box<dyn Iterator<Item = T> + 'a>
Given a path to an element of the struct and a range of possible values, return copies of all structs whose specified element is within the range.
§Example
let space = TreeObjectSpace::new();
space.write::<i64>(3);
space.write::<i64>(5);
assert_eq!(space.read_all_by_range::<i64, _>("", 2..4).count(), 1);
assert_eq!(space.read_all_by_range::<i64, _>("", 2..).count(), 2);
Sourcefn read_by_range<T, R>(&self, field: &str, range: R) -> T
fn read_by_range<T, R>(&self, field: &str, range: R) -> T
Given a path to an element of the struct and a range of possible values, return a copy of a struct whose specified element is within the range. The operation blocks until a struct satisfies the condition is found.
§Example
let space = TreeObjectSpace::new();
space.write::<i64>(3);
space.write::<i64>(5);
assert_eq!(space.read_by_range::<i64, _>("", 2..4), 3);
Sourcefn try_take_by_range<T, R>(&self, field: &str, range: R) -> Option<T>
fn try_take_by_range<T, R>(&self, field: &str, range: R) -> Option<T>
Given a path to an element of the struct and a range of possible values, remove and return a struct whose specified element is within the range. 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_range::<i64, _>("", 2..4), Some(3));
assert_eq!(space.try_take_by_range::<i64, _>("", 2..4), None);
assert_eq!(space.try_take_by_range::<i64, _>("", 2..), Some(5));
Sourcefn take_all_by_range<'a, T, R>(
&'a self,
field: &str,
range: R,
) -> Box<dyn Iterator<Item = T> + 'a>
fn take_all_by_range<'a, T, R>( &'a self, field: &str, range: R, ) -> Box<dyn Iterator<Item = T> + 'a>
Given a path to an element of the struct and a range of possible values, remove and return all structs whose specified element is within the range.
§Example
let space = TreeObjectSpace::new();
space.write::<i64>(3);
space.write::<i64>(5);
assert_eq!(space.take_all_by_range::<i64, _>("", 2..4).count(), 1);
assert_eq!(space.take_all_by_range::<i64, _>("", 2..).count(), 1);
Sourcefn take_by_range<T, R>(&self, field: &str, range: R) -> T
fn take_by_range<T, R>(&self, field: &str, range: R) -> T
Given a path to an element of the struct and a range of possible values, remove and return a struct whose specified element is within the range. The operation blocks until a struct satisfies the condition is found.
§Example
let space = TreeObjectSpace::new();
space.write::<i64>(3);
space.write::<i64>(5);
assert_eq!(space.take_by_range::<i64, _>("", 2..4), 3);
assert_eq!(space.take_by_range::<i64, _>("", 2..), 5);
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.