useself::get_span::{GetSpan, GetSpanBase, GetSpanInner}; usecrate::{IdentFragment, ToTokens, TokenStreamExt}; use core::fmt; use core::iter; use core::ops::BitOr; use proc_macro2::{Group, Ident, Punct, Spacing, TokenTree};
impl BitOr<ThereIsNoIteratorInRepetition> for ThereIsNoIteratorInRepetition { type Output = ThereIsNoIteratorInRepetition; fn bitor(self, _rhs: ThereIsNoIteratorInRepetition) -> ThereIsNoIteratorInRepetition {
ThereIsNoIteratorInRepetition
}
}
impl BitOr<ThereIsNoIteratorInRepetition> for HasIterator { type Output = HasIterator; fn bitor(self, _rhs: ThereIsNoIteratorInRepetition) -> HasIterator {
HasIterator
}
}
impl BitOr<HasIterator> for ThereIsNoIteratorInRepetition { type Output = HasIterator; fn bitor(self, _rhs: HasIterator) -> HasIterator {
HasIterator
}
}
impl BitOr<HasIterator> for HasIterator { type Output = HasIterator; fn bitor(self, _rhs: HasIterator) -> HasIterator {
HasIterator
}
}
/// Extension traits used by the implementation of `quote!`. These are defined /// in separate traits, rather than as a single trait due to ambiguity issues. /// /// These traits expose a `quote_into_iter` method which should allow calling /// whichever impl happens to be applicable. Calling that method repeatedly on /// the returned value should be idempotent. #[doc(hidden)] pubmod ext { usesuper::RepInterp; usesuper::{HasIterator as HasIter, ThereIsNoIteratorInRepetition as DoesNotHaveIter}; usecrate::ToTokens; use alloc::collections::btree_set::{self, BTreeSet}; use core::slice;
/// Extension trait providing the `quote_into_iter` method for /// non-iterable types. These types interpolate the same value in each /// iteration of the repetition. #[doc(hidden)] pubtrait RepToTokensExt { /// Pretend to be an iterator for the purposes of `quote_into_iter`. /// This allows repeated calls to `quote_into_iter` to continue /// correctly returning DoesNotHaveIter. fn next(&self) -> Option<&Self> {
Some(self)
}
impl<T: ToTokens + ?Sized> RepToTokensExt for T {}
/// Extension trait providing the `quote_into_iter` method for types that /// can be referenced as an iterator. #[doc(hidden)] pubtrait RepAsIteratorExt<'q> { type Iter: Iterator;
// Helper type used within interpolations to allow for repeated binding names. // Implements the relevant traits, and exports a dummy `next()` method. #[derive(Copy, Clone)] #[doc(hidden)] pubstruct RepInterp<T>(pub T);
impl<T> RepInterp<T> { // This method is intended to look like `Iterator::next`, and is called when // a name is bound multiple times, as the previous binding will shadow the // original `Iterator` object. This allows us to avoid advancing the // iterator multiple times per iteration. pubfn next(self) -> Option<T> {
Some(self.0)
}
}
impl<T: Iterator> Iterator for RepInterp<T> { type Item = T::Item;
// Token tree with every span replaced by the given one. fn respan_token_tree(mut token: TokenTree, span: Span) -> TokenTree { match &mut token {
TokenTree::Group(g) => { let stream = g
.stream()
.into_iter()
.map(|token| respan_token_tree(token, span))
.collect();
*g = Group::new(g.delimiter(), stream);
g.set_span(span);
}
other => other.set_span(span),
}
token
}
// Adapts from `IdentFragment` to `fmt::Display` for use by the `format_ident!` // macro, and exposes span information from these fragments. // // This struct also has forwarding implementations of the formatting traits // `Octal`, `LowerHex`, `UpperHex`, and `Binary` to allow for their use within // `format_ident!`. #[derive(Copy, Clone)] #[doc(hidden)] pubstruct IdentFragmentAdapter<T: IdentFragment>(pub T);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.