json_utils/query/query.rs
1use super::Path;
2
3pub trait Query<'v>: Sized {
4 type ItemRef: Sized + 'v;
5 type Item: Sized;
6
7 /// Lookup for an element under the specified path.
8 /// Returns an optional reference to the sought element.
9 fn lookup<'p, P>(&'v self, path: P) -> Option<Self::ItemRef>
10 where
11 P: Path<'p>;
12
13 /// Takes the element under the specified path out of the queried node.
14 /// Returns a tuple of two items:
15 /// - optinal remainder of the queried node;
16 /// - optinal taken away element.
17 fn take<'p, P>(self, path: P) -> (Option<Self>, Option<Self::Item>)
18 where
19 P: Path<'p>;
20
21 /// Inserts an element into the queried node under the specified path.
22 /// Returns Ok(()) if inserted or Err(rejected_element) if could not perform insertion
23 /// (e.g. path leads to a child of a non-object sub-node).
24 fn insert<'p, P>(&mut self, path: P, insertee: Self::Item) -> Result<(), Self::Item>
25 where
26 P: Path<'p>;
27}