pub struct QueryLibrary { /* private fields */ }Expand description
A collection of named queries parsed from a .jpx file.
Implementations§
Source§impl QueryLibrary
impl QueryLibrary
Sourcepub fn new() -> QueryLibrary
pub fn new() -> QueryLibrary
Create an empty query library.
Sourcepub fn parse(content: &str) -> Result<QueryLibrary, ParseError>
pub fn parse(content: &str) -> Result<QueryLibrary, ParseError>
Parse a query library from file content.
§Format
-- :name <name>starts a new query-- :desc <description>adds a description to the current query--other comment lines are ignored- Non-comment lines are appended to the current query’s expression
§Errors
Returns an error if:
- A query has an empty name
- A query has no expression
- Duplicate query names are found
- No queries are found in the content
§Example
use jpx_core::query_library::QueryLibrary;
let content = r#"
-- :name count
length(@)
"#;
let library = QueryLibrary::parse(content).unwrap();
assert_eq!(library.len(), 1);Sourcepub fn get(&self, name: &str) -> Option<&NamedQuery>
pub fn get(&self, name: &str) -> Option<&NamedQuery>
Get a query by name.
§Example
use jpx_core::query_library::QueryLibrary;
let lib = QueryLibrary::parse("-- :name test\nlength(@)").unwrap();
let query = lib.get("test").unwrap();
assert_eq!(query.expression, "length(@)");Sourcepub fn list(&self) -> &[NamedQuery]
pub fn list(&self) -> &[NamedQuery]
Get all queries.
§Example
use jpx_core::query_library::QueryLibrary;
let lib = QueryLibrary::parse("-- :name a\n`1`\n-- :name b\n`2`").unwrap();
assert_eq!(lib.list().len(), 2);Sourcepub fn names(&self) -> Vec<&str>
pub fn names(&self) -> Vec<&str>
Get query names.
§Example
use jpx_core::query_library::QueryLibrary;
let lib = QueryLibrary::parse("-- :name foo\n`1`\n-- :name bar\n`2`").unwrap();
assert_eq!(lib.names(), vec!["foo", "bar"]);Sourcepub fn iter(&self) -> impl Iterator<Item = &NamedQuery>
pub fn iter(&self) -> impl Iterator<Item = &NamedQuery>
Iterate over queries.
Trait Implementations§
Source§impl Clone for QueryLibrary
impl Clone for QueryLibrary
Source§fn clone(&self) -> QueryLibrary
fn clone(&self) -> QueryLibrary
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for QueryLibrary
impl Debug for QueryLibrary
Source§impl Default for QueryLibrary
impl Default for QueryLibrary
Source§fn default() -> QueryLibrary
fn default() -> QueryLibrary
Returns the “default value” for a type. Read more
Source§impl<'a> IntoIterator for &'a QueryLibrary
impl<'a> IntoIterator for &'a QueryLibrary
Source§type Item = &'a NamedQuery
type Item = &'a NamedQuery
The type of the elements being iterated over.
Source§type IntoIter = Iter<'a, NamedQuery>
type IntoIter = Iter<'a, NamedQuery>
Which kind of iterator are we turning this into?
Source§fn into_iter(self) -> <&'a QueryLibrary as IntoIterator>::IntoIter
fn into_iter(self) -> <&'a QueryLibrary as IntoIterator>::IntoIter
Creates an iterator from a value. Read more
Auto Trait Implementations§
impl Freeze for QueryLibrary
impl RefUnwindSafe for QueryLibrary
impl Send for QueryLibrary
impl Sync for QueryLibrary
impl Unpin for QueryLibrary
impl UnsafeUnpin for QueryLibrary
impl UnwindSafe for QueryLibrary
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<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more