Skip to main content

Fragment

Enum Fragment 

Source
#[non_exhaustive]
pub enum Fragment<K> { Tree, Kind(fn(&K) -> bool), }
Expand description

What a Pattern::Bind may capture: the fragment specifier.

macro-lang knows no grammar, so it cannot offer expr or ty fragments; those need a parser. What it can offer is the structural fragment every macro system has — any single token tree — and a token-level test the language supplies, which covers specifiers like ident and literal.

The enum is #[non_exhaustive] so that new fragment kinds can be added in a minor release; code that matches on a Fragment needs a wildcard arm.

§Examples

use macro_lang::Fragment;

// Any single tree: a token or a whole delimited group (`$x:tt`).
let any: Fragment<char> = Fragment::Tree;

// A single token whose kind passes a test (`$x:ident`).
let ident: Fragment<char> = Fragment::Kind(|c: &char| c.is_alphabetic());

assert!(matches!(any, Fragment::Tree));
assert!(matches!(ident, Fragment::Kind(test) if test(&'x') && !test(&'1')));

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

Tree

Any single token tree: one token, or one whole delimited group. This is the tt specifier.

§

Kind(fn(&K) -> bool)

A single token (never a group) whose kind satisfies the test — for example Fragment::Kind(Kind::is_ident) for an ident specifier.

Trait Implementations§

Source§

impl<K: Clone> Clone for Fragment<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 Fragment<K>

Source§

impl<K: Debug> Debug for Fragment<K>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<K> Forget for Fragment<K>

§

impl<K> Freeze for Fragment<K>
where fn(&K) -> bool: Freeze,

§

impl<K> Move for Fragment<K>

§

impl<K> RefUnwindSafe for Fragment<K>
where fn(&K) -> bool: RefUnwindSafe,

§

impl<K> Send for Fragment<K>
where fn(&K) -> bool: Send,

§

impl<K> Sync for Fragment<K>
where fn(&K) -> bool: Sync,

§

impl<K> Unpin for Fragment<K>
where fn(&K) -> bool: Unpin,

§

impl<K> UnsafeUnpin for Fragment<K>
where fn(&K) -> bool: UnsafeUnpin,

§

impl<K> UnwindSafe for Fragment<K>
where fn(&K) -> bool: 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.