use alloc::borrow::Cow; use core::fmt; use proc_macro2::{Ident, Span};
/// Specialized formatting trait used by `format_ident!`. /// /// [`Ident`] arguments formatted using this trait will have their `r#` prefix /// stripped, if present. /// /// See [`format_ident!`] for more information. /// /// [`format_ident!`]: crate::format_ident pubtrait IdentFragment { /// Format this value as an identifier fragment. fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result;
/// Span associated with this `IdentFragment`. /// /// If non-`None`, may be inherited by formatted identifiers. fn span(&self) -> Option<Span> {
None
}
}
impl<T: IdentFragment + ?Sized> IdentFragment for &T { fn span(&self) -> Option<Span> {
<T as IdentFragment>::span(*self)
}
// Limited set of types which this is implemented for, as we want to avoid types // which will often include non-identifier characters in their `Display` impl.
macro_rules! ident_fragment_display {
($($T:ty),*) => {
$( impl IdentFragment for $T { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fmt::Display::fmt(self, f)
}
}
)*
};
}
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.