[][src]Enum full_moon::ast::punctuated::Pair

pub enum Pair<'a, T> {
    End(T),
    Punctuated(T, TokenReference<'a>),
}

A node T followed by the possible trailing TokenReference. Refer to the module documentation for more details.

Variants

End(T)

A node T with no trailing punctuation

Punctuated(T, TokenReference<'a>)

A node T followed by punctuation (in the form of a TokenReference)

Methods

impl<'a, T> Pair<'a, T>[src]

pub fn new(value: T, punctuation: Option<TokenReference<'a>>) -> Self[src]

Creates a Pair with node T and optional punctuation

let pair = Pair::new(1, None);

pub fn into_tuple(self) -> (T, Option<TokenReference<'a>>)[src]

Takes the Pair and returns the node T and the punctuation, if it exists as a tuple

let pair = Pair::new(1, None);
assert_eq!(pair.into_tuple(), (1, None));

pub fn into_value(self) -> T[src]

Takes the Pair and returns the node T

let pair = Pair::new(1, None);
assert_eq!(pair.into_value(), 1);

pub fn value(&self) -> &T[src]

Returns a reference to the node T

let pair = Pair::new(1, None);
assert_eq!(pair.value(), &1);

pub fn value_mut(&mut self) -> &mut T[src]

Returns a mutable reference to the node T

let mut pair = Pair::new(1, None);
*pair.value_mut() += 1;
assert_eq!(pair.into_value(), 2);

pub fn punctuation(&self) -> Option<&TokenReference<'a>>[src]

Returns the trailing punctuation, if it exists

let pair = Pair::new(1, None);
assert_eq!(pair.punctuation(), None);

pub fn map<U, F: FnOnce(T) -> U>(self, f: F) -> Pair<'a, U>[src]

Maps a Pair<'a, T> to a Pair<'a, U> by applying a function to the value of the pair, while preserving punctuation if it is not the end.

let pair = Pair::new(2, None);
assert_eq!(*pair.map(|i| i * 2).value(), 4);

Trait Implementations

impl<'a, T: Clone> Clone for Pair<'a, T>[src]

impl<'a, T: Debug> Debug for Pair<'a, T>[src]

impl<'de: 'a, 'a, T> Deserialize<'de> for Pair<'a, T> where
    T: Deserialize<'de>, 
[src]

impl<'a, T> Extend<Pair<'a, T>> for Punctuated<'a, T>[src]

impl<'a, T: Node> Node for Pair<'a, T>[src]

impl<'_, T> Owned for Pair<'_, T> where
    T: Owned
[src]

type Owned = Pair<'static, <T as Owned>::Owned>

What an owned version of the object looks like. Usually contains a 'static lifetime.

impl<'a, T: PartialEq> PartialEq<Pair<'a, T>> for Pair<'a, T>[src]

impl<'a, T> Serialize for Pair<'a, T> where
    T: Serialize
[src]

impl<'a, T> StructuralPartialEq for Pair<'a, T>[src]

Auto Trait Implementations

impl<'a, T> !RefUnwindSafe for Pair<'a, T>

impl<'a, T> Send for Pair<'a, T> where
    T: Send

impl<'a, T> Sync for Pair<'a, T> where
    T: Sync

impl<'a, T> Unpin for Pair<'a, T> where
    T: Unpin

impl<'a, T> !UnwindSafe for Pair<'a, T>

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> DeserializeOwned for T where
    T: Deserialize<'de>, 
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.