pub struct XPath { /* private fields */ }Expand description
Cross Path allowing to recursively retrieve a FieldValue
from a structure implementing FieldGetter.
§Example:
use ::gene_derive::FieldGetter;
use ::gene::{XPath, FieldGetter, FieldValue};
#[derive(FieldGetter)]
struct LogData
{
a: String,
b: i32,
c: f64,
}
#[derive(FieldGetter)]
struct LogEntry
{
name: String,
data: LogData,
}
let e = LogEntry{
name: "SomeEntry".into(),
data: LogData{
a: "SomeData".into(),
b: 42,
c: 24.0,
}
};
let p = XPath::parse(".name").unwrap();
assert_eq!(e.get_from_path(&p), Some("SomeEntry".into()));
let p = XPath::parse(".data.a").unwrap();
assert_eq!(e.get_from_path(&p), Some("SomeData".into()));
let p = XPath::parse(".data.b").unwrap();
assert_eq!(e.get_from_path(&p), Some(42.into()));
let p = XPath::parse(".data.c").unwrap();
assert_eq!(e.get_from_path(&p), Some(24.0.into()));Implementations§
Source§impl XPath
impl XPath
Sourcepub fn segments(&self) -> &Vec<String>
pub fn segments(&self) -> &Vec<String>
getter to the segments of the path. If a path has been
built from .a.b.c the segments will be ["a", "b", "c"] as . is the
path segments separator
Sourcepub fn iter_segments(&self) -> Iter<'_, String>
pub fn iter_segments(&self) -> Iter<'_, String>
provides an iterator over the segments of the path
pub fn to_string_lossy(&self) -> Cow<'_, str>
Trait Implementations§
impl Eq for XPath
Auto Trait Implementations§
impl Freeze for XPath
impl RefUnwindSafe for XPath
impl Send for XPath
impl Sync for XPath
impl Unpin for XPath
impl UnwindSafe for XPath
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key and return true if they are equal.