Skip to main content

Pick

Enum Pick 

Source
#[non_exhaustive]
pub enum Pick<K> {
Show 16 variants Absent, Label(u16), Nth(u16), Back(u16), NthNode(u16), Kind(K), KindNth(K, u16), First(K), After(K), Before(K), All, Nodes, AllKind(K), Range(u16, u16), AllAfter(K), Between(K, K),
}
Expand description

Where a field of an archetype is found among a node’s children.

Positions count the node’s significant children: every child node and every token that is not trivia (whitespace and comments never count). List picks (All, Nodes, AllKind, Range, AllAfter, Between, and Label) select every match, splice the children of container kinds in place, and (except AllKind, Nodes, and Label) leave out skip kinds such as , and ; (both declared in the Mapping). Used where one child is expected, a list pick takes its first match.

A pick that finds nothing makes the field absent: optional fields are then left out, and required ones become an error node plus a MissingField problem.

§Examples

use lower_lang::Pick;

// `let NAME = VALUE ;` in a tree without labels: the name is the first
// identifier, the value is whatever follows `=`.
let ident = 7u16; // the language's IDENT kind
let eq = 9u16;    // its `=` kind
let name = Pick::Kind(ident);
let value = Pick::After(eq);
assert_ne!(name, value);
assert_eq!(Pick::<u16>::default(), Pick::Absent);

Variants (Non-exhaustive)§

This enum is marked as non-exhaustive
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
§

Absent

The construct never has this field.

§

Label(u16)

The child (or, as a list, every child) whose host-provided field label is this id. Needs a Labeler; without one it finds nothing.

§

Nth(u16)

The n-th significant child (0-based).

§

Back(u16)

The n-th significant child from the end (Back(0) is the last).

§

NthNode(u16)

The n-th child node (tokens not counted).

§

Kind(K)

The first significant child of this kind.

§

KindNth(K, u16)

The n-th significant child of this kind.

§

First(K)

The first significant child, if it is of this kind (a leading ::, a leading keyword).

§

After(K)

The first significant child after the first child of this kind (the value after =, the return type after ->).

§

Before(K)

The significant child just before the first child of this kind (the key before =>, the last item before )).

§

All

List: every significant child that is not a skip kind.

§

Nodes

List: every child node.

§

AllKind(K)

List: every significant child of this kind.

§

Range(u16, u16)

List: the significant children from position from up to back positions before the end (Range(1, 1) is everything between a node’s first and last child, such as the items between ( and )).

§

AllAfter(K)

List: every significant child after the first child of this kind.

§

Between(K, K)

List: the significant children after the first child of the first kind and before the next child of the second kind (or the end).

Implementations§

Source§

impl<K> Pick<K>

Source

pub const fn is_absent(&self) -> bool

Whether this pick names nothing (Absent).

§Examples
use lower_lang::Pick;

assert!(Pick::<u8>::Absent.is_absent());
assert!(!Pick::<u8>::Nth(0).is_absent());

Trait Implementations§

Source§

impl<K: Clone> Clone for Pick<K>

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<K: Copy> Copy for Pick<K>

Source§

impl<K: Debug> Debug for Pick<K>

Source§

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

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

impl<K> Default for Pick<K>

Source§

fn default() -> Self

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

impl<K: Eq> Eq for Pick<K>

Source§

impl<K: Hash> Hash for Pick<K>

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl<K: PartialEq> PartialEq for Pick<K>

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl<K: PartialEq> StructuralPartialEq for Pick<K>

Auto Trait Implementations§

§

impl<K> Freeze for Pick<K>
where K: Freeze,

§

impl<K> RefUnwindSafe for Pick<K>
where K: RefUnwindSafe,

§

impl<K> Send for Pick<K>
where K: Send,

§

impl<K> Sync for Pick<K>
where K: Sync,

§

impl<K> Unpin for Pick<K>
where K: Unpin,

§

impl<K> UnsafeUnpin for Pick<K>
where K: UnsafeUnpin,

§

impl<K> UnwindSafe for Pick<K>
where K: UnwindSafe,

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