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: Parse> Cached<T>
impl<T: Parse> Cached<T>
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§
impl<T: Parse> Eq for Cached<T>
Source§impl From<Cached<Group>> for Group
Convert CachedGroup into a Group`.
impl From<Cached<Group>> for Group
Convert CachedGroup into a Group`.
Source§fn from(cached: CachedGroup) -> Self
fn from(cached: CachedGroup) -> Self
Converts to this type from the input type.
Source§impl From<Cached<Ident>> for Ident
Convert CachedIdent into a Ident`.
impl From<Cached<Ident>> for Ident
Convert CachedIdent into a Ident`.
Source§fn from(cached: CachedIdent) -> Self
fn from(cached: CachedIdent) -> Self
Converts to this type from the input type.
Source§impl From<Cached<Literal>> for Literal
Convert CachedLiteral into a Literal`.
impl From<Cached<Literal>> for Literal
Convert CachedLiteral into a Literal`.
Source§fn from(cached: CachedLiteral) -> Self
fn from(cached: CachedLiteral) -> Self
Converts to this type from the input type.
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: CachedLiteralInteger) -> Self
fn from(cached: CachedLiteralInteger) -> Self
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: CachedLiteralString) -> Self
fn from(cached: CachedLiteralString) -> Self
Converts to this type from the input type.
Source§impl From<Cached<Punct>> for Punct
Convert CachedPunct into a Punct`.
impl From<Cached<Punct>> for Punct
Convert CachedPunct into a Punct`.
Source§fn from(cached: CachedPunct) -> Self
fn from(cached: CachedPunct) -> Self
Converts to this type from the input type.
Source§impl<T: Into<TokenTree>> From<Cached<T>> for TokenTree
Convert a Cached<T: Into<TokenTree>> object into a TokenTree.
impl<T: Into<TokenTree>> From<Cached<T>> for TokenTree
Convert a Cached<T: Into<TokenTree>> object into a TokenTree.
Source§impl<T: Parse + ToTokens> ToTokens for Cached<T>
impl<T: Parse + ToTokens> 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.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> UnsafeUnpin for Cached<T>where
T: UnsafeUnpin,
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>
fn parse(tokens: &mut TokenIter) -> Result<Self>
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