Skip to content

Commit

Permalink
Add example of using pair.punct_mut()
Browse files Browse the repository at this point in the history
  • Loading branch information
dtolnay committed Jun 2, 2022
1 parent f6ab69c commit 45b10cb
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/punctuated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -947,6 +947,22 @@ impl<T, P> Pair<T, P> {

/// Mutably borrows the punctuation from this punctuated pair, unless the
/// pair is the final one and there is no trailing punctuation.
///
/// # Example
///
/// ```
/// # use proc_macro2::Span;
/// # use syn::punctuated::Punctuated;
/// # use syn::{parse_quote, Token, TypeParamBound};
/// #
/// # let mut punctuated = Punctuated::<TypeParamBound, Token![+]>::new();
/// # let span = Span::call_site();
/// #
/// punctuated.insert(0, parse_quote!('lifetime));
/// if let Some(punct) = punctuated.pairs_mut().next().unwrap().punct_mut() {
/// punct.span = span;
/// }
/// ```
pub fn punct_mut(&mut self) -> Option<&mut P> {
match self {
Pair::Punctuated(_, p) => Some(p),
Expand Down

0 comments on commit 45b10cb

Please sign in to comment.