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
sourceimpl<T> Pair<T>
impl<T> Pair<T>
sourcepub fn new(value: T, punctuation: Option<TokenReference>) -> Self
pub fn new(value: T, punctuation: Option<TokenReference>) -> Self
Creates a Pair
with node T
and optional punctuation
let pair = Pair::new(1, None);
sourcepub fn into_tuple(self) -> (T, Option<TokenReference>)
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));
sourcepub fn into_value(self) -> T
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);
sourcepub fn value(&self) -> &T
pub fn value(&self) -> &T
Returns a reference to the node T
let pair = Pair::new(1, None);
assert_eq!(pair.value(), &1);
sourcepub fn value_mut(&mut self) -> &mut T
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);
sourcepub fn punctuation(&self) -> Option<&TokenReference>
pub fn punctuation(&self) -> Option<&TokenReference>
Returns the trailing punctuation, if it exists
let pair = Pair::new(1, None);
assert_eq!(pair.punctuation(), None);
Trait Implementations
sourceimpl<'de, T> Deserialize<'de> for Pair<T> where
T: Deserialize<'de>,
impl<'de, T> Deserialize<'de> for Pair<T> where
T: Deserialize<'de>,
sourcefn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error> where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error> where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
sourceimpl<T> Extend<Pair<T>> for Punctuated<T>
impl<T> Extend<Pair<T>> for Punctuated<T>
sourcefn extend<I: IntoIterator<Item = Pair<T>>>(&mut self, iter: I)
fn extend<I: IntoIterator<Item = Pair<T>>>(&mut self, iter: I)
Extends a collection with the contents of an iterator. Read more
sourcefn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one
)Extends a collection with exactly one element.
sourcefn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one
)Reserves capacity in a collection for the given number of additional elements. Read more
sourceimpl<T> FromIterator<Pair<T>> for Punctuated<T>
impl<T> FromIterator<Pair<T>> for Punctuated<T>
sourcefn from_iter<I: IntoIterator<Item = Pair<T>>>(iter: I) -> Self
fn from_iter<I: IntoIterator<Item = Pair<T>>>(iter: I) -> Self
Creates a value from an iterator. Read more
sourceimpl<T: Node> Node for Pair<T>
impl<T: Node> Node for Pair<T>
sourcefn start_position(&self) -> Option<Position>
fn start_position(&self) -> Option<Position>
The start position of a node. None if can’t be determined
sourcefn end_position(&self) -> Option<Position>
fn end_position(&self) -> Option<Position>
The end position of a node. None if it can’t be determined
sourcefn similar(&self, other: &Self) -> bool
fn similar(&self, other: &Self) -> bool
Whether another node of the same type is the same as this one semantically, ignoring position
sourcefn tokens(&self) -> Tokens<'_>ⓘNotable traits for Tokens<'a>impl<'a> Iterator for Tokens<'a> type Item = &'a TokenReference;
fn tokens(&self) -> Tokens<'_>ⓘNotable traits for Tokens<'a>impl<'a> Iterator for Tokens<'a> type Item = &'a TokenReference;
The token references that comprise a node
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
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcepub fn borrow_mut(&mut self) -> &mut T
pub fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcepub fn to_owned(&self) -> T
pub fn to_owned(&self) -> T
Creates owned data from borrowed data, usually by cloning. Read more
sourcepub fn clone_into(&self, target: &mut T)
pub fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more