pub struct Cached<T> { /* private fields */ }Expand description
Getting the underlying string expensive as it always allocates a new String.
This type caches the string representation of a given entity. Note that this is
only reliable for fundamental entities that represent a single token. Spacing between
composed tokens is not stable and should be considered informal only.
§Example
use unsynn::*;
let mut token_iter = "ident 1234".to_token_iter();
let cached_ident = Cached::<Ident>::parse(&mut token_iter).unwrap();
assert!(cached_ident == "ident");Implementations§
Source§impl<T> Cached<T>where
T: Parse,
impl<T> Cached<T>where
T: Parse,
Sourcepub fn into_inner(self) -> T
pub fn into_inner(self) -> T
Deconstructs self and returns the inner value.
Sourcepub fn into_string(self) -> String
pub fn into_string(self) -> String
Deconstructs self and returns the contained String representation.
Trait Implementations§
Source§impl From<Cached<LiteralInteger>> for LiteralInteger
Convert CachedLiteralInteger into a LiteralInteger`.
impl From<Cached<LiteralInteger>> for LiteralInteger
Convert CachedLiteralInteger into a LiteralInteger`.
Source§fn from(cached: Cached<LiteralInteger>) -> LiteralInteger
fn from(cached: Cached<LiteralInteger>) -> LiteralInteger
Converts to this type from the input type.
Source§impl From<Cached<LiteralString>> for LiteralString
Convert CachedLiteralString into a LiteralString`.
impl From<Cached<LiteralString>> for LiteralString
Convert CachedLiteralString into a LiteralString`.
Source§fn from(cached: Cached<LiteralString>) -> LiteralString
fn from(cached: Cached<LiteralString>) -> LiteralString
Converts to this type from the input type.
Source§impl<T> From<Cached<T>> for TokenTree
Convert a Cached<T: Into<TokenTree>> object into a TokenTree.
impl<T> From<Cached<T>> for TokenTree
Convert a Cached<T: Into<TokenTree>> object into a TokenTree.
Source§impl<T> Parser for Cached<T>
impl<T> Parser for Cached<T>
Source§fn parser(tokens: &mut TokenIter) -> Result<Cached<T>, Error>
fn parser(tokens: &mut TokenIter) -> Result<Cached<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 Cached<T>
impl<T> ToTokens for Cached<T>
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.Source§impl<T> TryFrom<&str> for Cached<T>where
T: Parse,
Available on crate feature proc_macro2 only.
impl<T> TryFrom<&str> for Cached<T>where
T: Parse,
Available on crate feature
proc_macro2 only.Source§impl<T> TryFrom<String> for Cached<T>where
T: Parse,
Available on crate feature proc_macro2 only.
impl<T> TryFrom<String> for Cached<T>where
T: Parse,
Available on crate feature
proc_macro2 only.impl<T> Eq for Cached<T>where
T: Parse,
Auto Trait Implementations§
impl<T> Freeze for Cached<T>where
T: Freeze,
impl<T> RefUnwindSafe for Cached<T>where
T: RefUnwindSafe,
impl<T> Send for Cached<T>where
T: Send,
impl<T> Sync for Cached<T>where
T: Sync,
impl<T> Unpin for Cached<T>where
T: Unpin,
impl<T> UnwindSafe for Cached<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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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