Skip to main content

LookupSet

Struct LookupSet 

Source
pub struct LookupSet<'s, 'i, T: Hash + Eq, V = &'s T> { /* private fields */ }
Expand description

Result of a lookup by name in a Scope.

Elements represented by a LookupSet can be filtered and transformed using the filter(), map(), filter_map(), and filter_map_ok() functions, which work similarly to their counterpart on iterators. LookupSet<T, V> represents elements coming from a Scope<T> and transformed (by map() or filter_map()) into elements of type V.

The difference from a standard iterator is that LookupSet remembers enough information to allow the one() method to emit detailed error diagnostics. See one() for details.

Implementations§

Source§

impl<'s, 'i, T: 's + Hash + Eq, V: 's> LookupSet<'s, 'i, T, V>

Source

pub fn name(&self) -> &Identifier<'_>

Get the Identifier the LookupSet was looked up for.

Source

pub fn is_empty(&self) -> bool

Tell if the LookupSet is empty.

Source

pub fn filter_map_ok<R: 's>( self, f: impl 's + Fn(V) -> Result<Option<R>>, ) -> LookupSet<'s, 'i, T, R>

Get a LookupSet of only the elements of self transformed by the function f for only the elements v where f(v) returns Ok(Some(_)). If f returns Err(_), the whole LookupSet becomes erroneous and any call to all() or one() will return the same Err(_).

Source

pub fn filter_map<R: 's>( self, f: impl 's + Fn(V) -> Option<R>, ) -> LookupSet<'s, 'i, T, R>

Get a LookupSet of the elements of self transformed by the function f for only the elements v where f(v) returns Some(_).

Source

pub fn filter(self, f: impl 's + Fn(&V) -> bool) -> Self

Get a LookupSet of only the elements of self that satisfy the predicate f.

Source

pub fn filter_ok(self, f: impl 's + Fn(&V) -> Result<bool>) -> Self

Get a LookupSet of only the elements v of self such that f(v) returns Ok(true). If Ok(false) is returned, the element is discarded. If Err(_) is returned, the whole LookupSet becomes erroneous and any call to all() or one() will return the same Err(_).

Source

pub fn map<R: 's>(self, f: impl 's + Fn(V) -> R) -> LookupSet<'s, 'i, T, R>

Get a LookupSet of the elements of self transformed by the function f

Source

pub fn all(self) -> Result<Vec<V>>

Get an iterator of all the elements in the LookupSet.

Source

pub fn or_else( self, other: impl 's + FnOnce() -> LookupSet<'s, 'i, T, V>, ) -> Self

If the current LookupSet is not empty, return it as-is, otherwise call the other closure and return its result.

Source§

impl<'s, 'i, T: 's + Clone + Hash + Eq + Located, V: 's> LookupSet<'s, 'i, T, V>

Source

pub fn one(self) -> Result<V>

Return the single element in this LookupSet if only one exist, otherwise produce detailed error diagnostics.

The one() method assumes its usage is within name lookup for a typical statically scoped language (this includes quantifiers or other similar constructs in most logics). By calling this method one asserts that only a single result of the previous call to lookup() is required. If this is the case, the single result is returned. Otherwise, error diagnostics are produced.

The diagnostics are produced after checking further conditions. If there were more than one element the lookup is treated as ambiguous (as if you asked for the name of an overloaded function in some C++-like language without specifying its argument types) and a list of matching symbols is produced as attached notes. If the LookupSet is empty the lookup is treated as a reference to an undefined symbol, but if it was filtered (see filter()), then a list of non-matching symbols is produced as attached notes.

Auto Trait Implementations§

§

impl<'s, 'i, T, V = &'s T> !RefUnwindSafe for LookupSet<'s, 'i, T, V>

§

impl<'s, 'i, T, V = &'s T> !Send for LookupSet<'s, 'i, T, V>

§

impl<'s, 'i, T, V = &'s T> !Sync for LookupSet<'s, 'i, T, V>

§

impl<'s, 'i, T, V = &'s T> !UnwindSafe for LookupSet<'s, 'i, T, V>

§

impl<'s, 'i, T, V> Freeze for LookupSet<'s, 'i, T, V>
where &'s Scope<T>: Freeze, Box<dyn Iterator<Item = &'s T> + 's>: Freeze, Box<dyn Fn(&'s T) -> Result<Option<V>, DiagnosticEmitted> + 's>: Freeze,

§

impl<'s, 'i, T, V> Unpin for LookupSet<'s, 'i, T, V>
where &'s Scope<T>: Unpin, Box<dyn Iterator<Item = &'s T> + 's>: Unpin, Box<dyn Fn(&'s T) -> Result<Option<V>, DiagnosticEmitted> + 's>: Unpin,

§

impl<'s, 'i, T, V> UnsafeUnpin for LookupSet<'s, 'i, T, V>
where &'s Scope<T>: UnsafeUnpin, Box<dyn Iterator<Item = &'s T> + 's>: UnsafeUnpin, Box<dyn Fn(&'s T) -> Result<Option<V>, DiagnosticEmitted> + 's>: UnsafeUnpin,

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> 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, 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.