Skip to main content

Variants

Struct Variants 

Source
pub struct Variants(/* private fields */);
Expand description

Element extractor that pulls enum variants from the input.

Errors at compile time if the input is not an enum. Access the inner Punctuated<syn::Variant, syn::token::Comma> via Deref or the inner() method.

#[zyn::element]
fn my_element(#[zyn(input)] variants: zyn::Variants) -> proc_macro2::TokenStream {
    // variants.iter() — accessed via Deref to Punctuated<syn::Variant, syn::token::Comma>
}

Implementations§

Source§

impl Variants

Source

pub fn inner(self) -> Punctuated<Variant, Comma>

Consumes the wrapper and returns the inner Punctuated<syn::Variant, syn::token::Comma>.

Methods from Deref<Target = Punctuated<Variant, Comma>>§

Source

pub fn is_empty(&self) -> bool

Determines whether this punctuated sequence is empty, meaning it contains no syntax tree nodes or punctuation.

Source

pub fn len(&self) -> usize

Returns the number of syntax tree nodes in this punctuated sequence.

This is the number of nodes of type T, not counting the punctuation of type P.

Source

pub fn first(&self) -> Option<&T>

Borrows the first element in this sequence.

Source

pub fn first_mut(&mut self) -> Option<&mut T>

Mutably borrows the first element in this sequence.

Source

pub fn last(&self) -> Option<&T>

Borrows the last element in this sequence.

Source

pub fn last_mut(&mut self) -> Option<&mut T>

Mutably borrows the last element in this sequence.

Source

pub fn get(&self, index: usize) -> Option<&T>

Borrows the element at the given index.

Source

pub fn get_mut(&mut self, index: usize) -> Option<&mut T>

Mutably borrows the element at the given index.

Source

pub fn iter(&self) -> Iter<'_, T>

Returns an iterator over borrowed syntax tree nodes of type &T.

Source

pub fn iter_mut(&mut self) -> IterMut<'_, T>

Returns an iterator over mutably borrowed syntax tree nodes of type &mut T.

Source

pub fn pairs(&self) -> Pairs<'_, T, P>

Returns an iterator over the contents of this sequence as borrowed punctuated pairs.

Source

pub fn pairs_mut(&mut self) -> PairsMut<'_, T, P>

Returns an iterator over the contents of this sequence as mutably borrowed punctuated pairs.

Source

pub fn push_value(&mut self, value: T)

Appends a syntax tree node onto the end of this punctuated sequence. The sequence must already have a trailing punctuation, or be empty.

Use push instead if the punctuated sequence may or may not already have trailing punctuation.

§Panics

Panics if the sequence is nonempty and does not already have a trailing punctuation.

Source

pub fn push_punct(&mut self, punctuation: P)

Appends a trailing punctuation onto the end of this punctuated sequence. The sequence must be non-empty and must not already have trailing punctuation.

§Panics

Panics if the sequence is empty or already has a trailing punctuation.

Source

pub fn pop(&mut self) -> Option<Pair<T, P>>

Removes the last punctuated pair from this sequence, or None if the sequence is empty.

Source

pub fn pop_punct(&mut self) -> Option<P>

Removes the trailing punctuation from this punctuated sequence, or None if there isn’t any.

Source

pub fn trailing_punct(&self) -> bool

Determines whether this punctuated sequence ends with a trailing punctuation.

Source

pub fn empty_or_trailing(&self) -> bool

Returns true if either this Punctuated is empty, or it has a trailing punctuation.

Equivalent to punctuated.is_empty() || punctuated.trailing_punct().

Source

pub fn push(&mut self, value: T)
where P: Default,

Appends a syntax tree node onto the end of this punctuated sequence.

If there is not a trailing punctuation in this sequence when this method is called, the default value of punctuation type P is inserted before the given value of type T.

Source

pub fn insert(&mut self, index: usize, value: T)
where P: Default,

Inserts an element at position index.

§Panics

Panics if index is greater than the number of elements previously in this punctuated sequence.

Source

pub fn clear(&mut self)

Clears the sequence of all values and punctuation, making it empty.

Trait Implementations§

Source§

impl Deref for Variants

Source§

type Target = Punctuated<Variant, Comma>

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.
Source§

impl DerefMut for Variants

Source§

fn deref_mut(&mut self) -> &mut Self::Target

Mutably dereferences the value.
Source§

impl FromInput for Variants

Source§

fn from_input(input: &Input) -> Result<Self>

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> 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<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

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

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.