pub struct QueryAliases { /* private fields */ }Expand description
An ordered set of named query definitions.
§Examples
use molframe_query::{Query, QueryAliases};
let compile = |source| match Query::compile(source) {
Ok(query) => query,
Err(findings) => panic!("{findings:?}"),
};
let mut aliases = QueryAliases::new();
assert!(aliases.define("heme", compile("resname HEM")).is_ok());
let pocket = compile("byres (within 5 of $heme) and protein");
let Ok(closed) = aliases.resolve(&pocket) else {
panic!("every name is defined");
};
assert!(closed.references().is_empty());
assert_eq!(
closed.fingerprint(),
compile("byres (within 5 of (resname HEM)) and protein").fingerprint(),
);Implementations§
Source§impl QueryAliases
impl QueryAliases
Sourcepub const MAX_DEPTH: usize = 64
pub const MAX_DEPTH: usize = 64
The deepest chain of references resolution follows before refusing.
Interactive definitions nest a handful of levels deep; the bound exists so that a pathological or adversarial chain cannot exhaust the stack.
Sourcepub fn is_valid_name(name: &str) -> bool
pub fn is_valid_name(name: &str) -> bool
Whether name is spelled as a definable name.
A name starts with an ASCII letter or underscore and continues with
ASCII letters, digits and underscores, which is exactly what may follow
$ in a query.
Sourcepub fn define(
&mut self,
name: impl Into<Box<str>>,
query: Query,
) -> Result<Option<Query>, Diagnostic>
pub fn define( &mut self, name: impl Into<Box<str>>, query: Query, ) -> Result<Option<Query>, Diagnostic>
Defines or redefines name, returning the definition it replaced.
The definition is stored as written: its own references are resolved when a query that uses it is resolved, so redefining a name it depends on changes what it means.
§Errors
Returns a syntax diagnostic when name is not a valid name.
Sourcepub fn resolve(&self, query: &Query) -> Result<Query, Vec<Diagnostic>>
pub fn resolve(&self, query: &Query) -> Result<Query, Vec<Diagnostic>>
Replaces every named reference in query with its definition.
The result mentions no name, so it can be evaluated, fingerprinted or sent elsewhere without these definitions. A query with no references is returned unchanged, source text included.
§Errors
Returns E4005 for a name with no definition, E4006 for definitions
that refer to each other in a cycle, and E4007 when references nest
deeper than Self::MAX_DEPTH.
Trait Implementations§
Source§impl Clone for QueryAliases
impl Clone for QueryAliases
Source§impl Debug for QueryAliases
impl Debug for QueryAliases
Auto Trait Implementations§
impl Freeze for QueryAliases
impl RefUnwindSafe for QueryAliases
impl Send for QueryAliases
impl Sync for QueryAliases
impl Unpin for QueryAliases
impl UnsafeUnpin for QueryAliases
impl UnwindSafe for QueryAliases
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
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> ⓘ
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> ⓘ
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