pub enum Pair<T> {
    End(T),
    Punctuated(T, TokenReference),
}
Expand description

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 node T followed by punctuation (in the form of a TokenReference)

Implementations§

source§

impl<T> Pair<T>

source

pub fn new(value: T, punctuation: Option<TokenReference>) -> Self

Creates a Pair with node T and optional punctuation

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

pub fn into_tuple(self) -> (T, Option<TokenReference>)

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));
source

pub fn into_value(self) -> T

Takes the Pair and returns the node T

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

pub fn value(&self) -> &T

Returns a reference to the node T

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

pub fn value_mut(&mut self) -> &mut T

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);
source

pub fn punctuation(&self) -> Option<&TokenReference>

Returns the trailing punctuation, if it exists

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

pub fn map<U, F: FnOnce(T) -> U>(self, f: F) -> Pair<U>

Maps a Pair<T> to a Pair<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§

source§

impl<T: Clone> Clone for Pair<T>

source§

fn clone(&self) -> Pair<T>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<T: Debug> Debug for Pair<T>

source§

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

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

impl<'de, T> Deserialize<'de> for Pair<T>where T: Deserialize<'de>,

source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
source§

impl<T> Display for Pair<T>where T: Display,

source§

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

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

impl<T> Extend<Pair<T>> for Punctuated<T>

source§

fn extend<I: IntoIterator<Item = Pair<T>>>(&mut self, iter: I)

Extends a collection with the contents of an iterator. Read more
source§

fn extend_one(&mut self, item: A)

🔬This is a nightly-only experimental API. (extend_one)
Extends a collection with exactly one element.
source§

fn extend_reserve(&mut self, additional: usize)

🔬This is a nightly-only experimental API. (extend_one)
Reserves capacity in a collection for the given number of additional elements. Read more
source§

impl<T> FromIterator<Pair<T>> for Punctuated<T>

source§

fn from_iter<I: IntoIterator<Item = Pair<T>>>(iter: I) -> Self

Creates a value from an iterator. Read more
source§

impl<T: Node> Node for Pair<T>

source§

fn start_position(&self) -> Option<Position>

The start position of a node. None if can’t be determined
source§

fn end_position(&self) -> Option<Position>

The end position of a node. None if it can’t be determined
source§

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

Whether another node of the same type is the same as this one semantically, ignoring position
source§

fn tokens(&self) -> Tokens<'_>

The token references that comprise a node
source§

fn range(&self) -> Option<(Position, Position)>

The full range of a node, if it has both start and end positions
source§

fn surrounding_trivia(&self) -> (Vec<&Token>, Vec<&Token>)

The tokens surrounding a node that are ignored and not accessible through the node’s own accessors. Use this if you want to get surrounding comments or whitespace. Returns a tuple of the leading and trailing trivia.
source§

impl<T: PartialEq> PartialEq for Pair<T>

source§

fn eq(&self, other: &Pair<T>) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<T> Serialize for Pair<T>where T: Serialize,

source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
source§

impl<T: Eq> Eq for Pair<T>

source§

impl<T> StructuralEq for Pair<T>

source§

impl<T> StructuralPartialEq for Pair<T>

Auto Trait Implementations§

§

impl<T> RefUnwindSafe for Pair<T>where T: RefUnwindSafe,

§

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

§

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

§

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

§

impl<T> UnwindSafe for Pair<T>where T: UnwindSafe,

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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 Twhere 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 Twhere T: Clone,

§

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> ToString for Twhere T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

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

§

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 Twhere U: TryFrom<T>,

§

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

impl<T> DeserializeOwned for Twhere T: for<'de> Deserialize<'de>,