Trait object_space::ValueLookupObjectSpace[][src]

pub trait ValueLookupObjectSpace<U>: ObjectSpace {
    fn try_read_by_value<T>(&self, field: &str, key: &U) -> Option<T>
    where
        T: Serialize + Deserialize<'de> + 'static
;
fn read_all_by_value<'a, T>(
        &'a self,
        field: &str,
        key: &U
    ) -> Box<Iterator<Item = T> + 'a>
    where
        T: Deserialize<'de> + 'static
;
fn read_by_value<T>(&self, field: &str, key: &U) -> T
    where
        T: Serialize + Deserialize<'de> + 'static
;
fn try_take_by_value<T>(&self, field: &str, key: &U) -> Option<T>
    where
        T: Serialize + Deserialize<'de> + 'static
;
fn take_all_by_value<'a, T>(
        &'a self,
        field: &str,
        key: &U
    ) -> Box<Iterator<Item = T> + 'a>
    where
        T: Deserialize<'de> + 'static
;
fn take_by_value<T>(&self, field: &str, key: &U) -> T
    where
        T: Serialize + Deserialize<'de> + 'static
; }

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

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

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

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

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

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

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

Implementors