#[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§
Auto Trait Implementations§
impl<K> Forget for Fragment<K>
impl<K> Freeze for Fragment<K>
impl<K> Move for Fragment<K>
impl<K> RefUnwindSafe for Fragment<K>
impl<K> Send for Fragment<K>
impl<K> Sync for Fragment<K>
impl<K> Unpin for Fragment<K>
impl<K> UnsafeUnpin for Fragment<K>
impl<K> UnwindSafe for Fragment<K>
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
Mutably borrows from an owned value. Read more