Repository navigation
Expand file tree
/
Copy pathtarget.rs
More file actions
53 lines (50 loc) · 1.59 KB
/
Copy pathtarget.rs
File metadata and controls
53 lines (50 loc) · 1.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
use crate::{Path, Value};
/// Any target object you want to remap using VRL has to implement this trait.
pub trait Target: std::fmt::Debug {
/// Insert a given [`Value`] in the provided [`Target`].
///
/// The `path` parameter determines _where_ in the given target the value
/// should be inserted.
///
/// A path consists of "path segments". Each segment can be one of:
///
/// * regular path segments:
///
/// ```txt
/// .foo.bar.baz
/// ```
///
/// * quoted path segments:
///
/// ```txt
/// .foo."bar.baz"
/// ```
///
/// * coalesced path segments:
///
/// ```txt
/// .foo.(bar | "bar.baz").qux
/// ```
///
/// * path indices:
///
/// ```txt
/// .foo[2][-1]
/// ```
///
/// When inserting into a coalesced path, the implementor is encouraged to
/// insert into the right-most segment if none exists, but can return an
/// error if needed.
fn insert(&mut self, path: &Path, value: Value) -> Result<(), String>;
/// Get a value for a given path, or `None` if no value is found.
///
/// See [`Object::insert`] for more details.
fn get(&self, path: &Path) -> Result<Option<Value>, String>;
/// Remove the given path from the object.
///
/// Returns the removed object, if any.
///
/// If `compact` is true, after deletion, if an empty object or array is
/// left behind, it should be removed as well, cascading up to the root.
fn remove(&mut self, path: &Path, compact: bool) -> Result<Option<Value>, String>;
}