use proc_macro2::{Span, TokenStream}; use quote::ToTokens; use syn::{Ident, Meta};
usecrate::{FromMeta, Result};
/// A wrapper for an `Ident` which also keeps the value as a string. /// /// This struct can be used to perform string comparisons and operations. #[derive(Clone, PartialOrd, Ord)] pubstruct IdentString {
ident: Ident,
string: String,
}
/// Get the ident as a `proc_macro2::Ident`. pubfn as_ident(&self) -> &Ident {
&self.ident
}
/// Get the ident as a string. pubfn as_str(&self) -> &str {
&self.string
}
/// Get the location of this `Ident` in source. pubfn span(&self) -> Span { self.ident.span()
}
/// Apply some transform to the ident's string representation. /// /// # Panics /// This will panic if the transform produces an invalid ident. pubfn map<F, S>(self, map_fn: F) -> Self where
F: FnOnce(String) -> S,
S: AsRef<str>,
{ let span = self.span(); let string = map_fn(self.string);
Ident::new(string.as_ref(), span).into()
}
}
#[test] fn map_transform() { let i = IdentString::new(parse_quote!(my)); let after = i.map(|v| format!("var_{}", v));
assert_eq!(after, "var_my");
assert_eq!(after, String::from("var_my"));
}
}
Messung V0.5 in Prozent
¤ Dauer der Verarbeitung: 0.12 Sekunden
(vorverarbeitet am 2026-06-23)
¤
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.