Trait object_space::RangeLookupObjectSpace[][src]

pub trait RangeLookupObjectSpace<U>: ObjectSpace {
    fn try_read_by_range<T, R>(&self, field: &str, range: R) -> Option<T>
    where
        T: Serialize + Deserialize<'de> + 'static,
        R: RangeBounds<U> + Clone
;
fn read_all_by_range<'a, T, R>(
        &'a self,
        field: &str,
        range: R
    ) -> Box<Iterator<Item = T> + 'a>
    where
        T: Deserialize<'de> + 'static,
        R: RangeBounds<U> + Clone
;
fn read_by_range<T, R>(&self, field: &str, range: R) -> T
    where
        T: Serialize + Deserialize<'de> + 'static,
        R: RangeBounds<U> + Clone
;
fn try_take_by_range<T, R>(&self, field: &str, range: R) -> Option<T>
    where
        T: Serialize + Deserialize<'de> + 'static,
        R: RangeBounds<U> + Clone
;
fn take_all_by_range<'a, T, R>(
        &'a self,
        field: &str,
        range: R
    ) -> Box<Iterator<Item = T> + 'a>
    where
        T: Deserialize<'de> + 'static,
        R: RangeBounds<U> + Clone
;
fn take_by_range<T, R>(&self, field: &str, range: R) -> T
    where
        T: Serialize + Deserialize<'de> + 'static,
        R: RangeBounds<U> + Clone
; }

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

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

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

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

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

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

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

Implementors