Skip to main content

QueryAliases

Struct QueryAliases 

Source
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

Source

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.

Source

pub fn new() -> Self

An empty set of definitions.

Source

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.

Source

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.

Source

pub fn remove(&mut self, name: &str) -> Option<Query>

Removes name, returning its definition.

Source

pub fn get(&self, name: &str) -> Option<&Query>

The definition of name, as written.

Source

pub fn contains(&self, name: &str) -> bool

Whether name is defined.

Source

pub fn names(&self) -> impl Iterator<Item = &str>

Defined names in ascending order.

Source

pub fn len(&self) -> usize

Number of definitions.

Source

pub fn is_empty(&self) -> bool

Whether nothing is defined.

Source

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

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for QueryAliases

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for QueryAliases

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.