pub struct Query { /* private fields */ }Expand description
Represents a pre-compiled query.
A query can be obtained using Doc::compile. And then repeatedly being executed using Query::execute{Query::execute}.
Compiling a query essentially splits the given query string at “.” and then resolves each
part of the query into a Symbol. Therefore a query compiled for one Doc cannot be used
for another as its result would be entirely undefined. Also note that compiling queries is
rather fast, therefore ad-hoc queries can be executed using Element::query.
Implementations§
Source§impl Query
impl Query
Sourcepub fn execute<'a>(&self, element: Element<'a>) -> Element<'a>
pub fn execute<'a>(&self, element: Element<'a>) -> Element<'a>
Executes the query against the given element.
Note that the element must be part of the same doc for which the query has been compiled otherwise the return value is undefined.
§Example
let mut builder = DocBuilder::new();
let mut object_builder = builder.root_object_builder();
object_builder.put_object("Foo").unwrap().put_int("Bar", 42).unwrap();
let doc = builder.build();
let query = doc.compile("Foo.Bar");
assert_eq!(query.execute(doc.root()).as_int().unwrap(), 42)Trait Implementations§
Auto Trait Implementations§
impl Freeze for Query
impl RefUnwindSafe for Query
impl Send for Query
impl Sync for Query
impl Unpin for Query
impl UnwindSafe for Query
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