pub struct IntoIdent<T>(/* private fields */);Expand description
Parses T and concats all its elements to a single identifier by removing all characters
that are not valid in identifiers. When T implements Default, such as single string
(non group) keywords, operators and Const* literals. Then it can be used to create
IntoIdentifier on the fly. Note that construction may still fail when one tries to
create a invalid identifier such as one starting with digits for example.
§Example
let mut token_iter = "foo 123".to_token_iter();
let parsed = <IntoIdent<Cons<Ident, LiteralInteger>>>::parser(&mut token_iter).unwrap();
assert_tokens_eq!(parsed, "foo123");
keyword!{Foo = "foo"}
let default = <IntoIdent<Cons<Foo, ConstInteger<1234>>>>::default();
assert_tokens_eq!(default, "foo1234");Implementations§
Source§impl<T> IntoIdent<T>where
T: ToTokens,
impl<T> IntoIdent<T>where
T: ToTokens,
Sourcepub fn from(from: &T) -> Result<IntoIdent<T>, Error>
pub fn from(from: &T) -> Result<IntoIdent<T>, Error>
Creates a IntoIdent from an AST.
§Errors
This function returns an error when the provided data cannot be parsed as an identifier.
let mut token_iter = r#" foo "123" "#.to_token_iter();
let parsed = <Cons<Ident, LiteralString>>::parser(&mut token_iter).unwrap();
let ident = IntoIdent::from(&parsed).unwrap();
assert_eq!(ident.as_str(), "foo123");Trait Implementations§
Source§impl<T> Default for IntoIdent<T>
Available on crate feature proc_macro2 only.Creates a default constructed IntoIdent<T> from T
impl<T> Default for IntoIdent<T>
Available on crate feature
proc_macro2 only.Creates a default constructed IntoIdent<T> from T
§Panics
When the concatenation of T does not form a valid Ident.
Source§impl<T> From<IntoIdent<T>> for Ident
Available on crate feature proc_macro2 only.Converts IntoIdent<T> into Ident by consuming the IntoIdent<T>.
impl<T> From<IntoIdent<T>> for Ident
Available on crate feature
proc_macro2 only.Converts IntoIdent<T> into Ident by consuming the IntoIdent<T>.
Source§impl<T> Parser for IntoIdent<T>
Available on crate feature proc_macro2 only.
impl<T> Parser for IntoIdent<T>
Available on crate feature
proc_macro2 only.Source§fn parser(tokens: &mut TokenIter) -> Result<IntoIdent<T>, Error>
fn parser(tokens: &mut TokenIter) -> Result<IntoIdent<T>, Error>
The actual parsing function that must be implemented. This mutates the
tokens
iterator directly. It should not be called from user code except for implementing
parsers itself and then only when the rules below are followed. Read moreSource§impl<T> ToTokens for IntoIdent<T>where
T: ToTokens,
Available on crate feature proc_macro2 only.
impl<T> ToTokens for IntoIdent<T>where
T: ToTokens,
Available on crate feature
proc_macro2 only.Source§fn to_tokens(&self, tokens: &mut TokenStream)
fn to_tokens(&self, tokens: &mut TokenStream)
Source§fn into_token_iter(self) -> TokenIter ⓘwhere
Self: Sized,
fn into_token_iter(self) -> TokenIter ⓘwhere
Self: Sized,
Convert
self into a TokenIter object.Source§fn to_token_stream(&self) -> TokenStream
fn to_token_stream(&self) -> TokenStream
Convert
&self into a TokenStream object.Source§fn into_token_stream(self) -> TokenStreamwhere
Self: Sized,
fn into_token_stream(self) -> TokenStreamwhere
Self: Sized,
Convert
self into a TokenStream object.Auto Trait Implementations§
impl<T> Freeze for IntoIdent<T>
impl<T> RefUnwindSafe for IntoIdent<T>where
T: RefUnwindSafe,
impl<T> !Send for IntoIdent<T>
impl<T> !Sync for IntoIdent<T>
impl<T> Unpin for IntoIdent<T>where
T: Unpin,
impl<T> UnwindSafe for IntoIdent<T>where
T: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> DynamicTokens for T
impl<T> DynamicTokens for T
Source§impl<T> Parse for Twhere
T: Parser,
impl<T> Parse for Twhere
T: Parser,
Source§fn parse(tokens: &mut TokenIter) -> Result<Self, Error>
fn parse(tokens: &mut TokenIter) -> Result<Self, Error>
This is the user facing API to parse grammatical entities. Calls a
parser() within a
transaction. Commits changes on success and returns the parsed value. Read more