Trait synthez_core::parse::BufferExt
source · pub trait BufferExt: Sealed {
// Required methods
fn try_parse<T: Default + Parse + Token>(&self) -> Result<Option<T>>;
fn is_next<T: Default + Token>(&self) -> bool;
fn parse_any_ident(&self) -> Result<Ident>;
fn parse_wrapped_and_punctuated<T, W, P>(&self) -> Result<Punctuated<T, P>>
where T: Parse,
W: Default + Token + AcceptedWrapper + 'static,
P: Default + Parse + Token;
fn parse_maybe_wrapped_and_punctuated<T, W, P>(
&self
) -> Result<Punctuated<T, P>>
where T: Parse,
W: Default + Token + AcceptedWrapper + 'static,
P: Default + Parse + Token;
fn parse_eq_or_wrapped_and_punctuated<T, W, P>(
&self
) -> Result<Punctuated<T, P>>
where T: Parse,
W: Default + Token + AcceptedWrapper + 'static,
P: Default + Parse + Token;
// Provided method
fn skip_any_ident(&self) -> Result<()> { ... }
}
Expand description
Extension of a syn::parse::ParseBuffer
providing common function widely
used by this crate for parsing.
Required Methods§
sourcefn try_parse<T: Default + Parse + Token>(&self) -> Result<Option<T>>
fn try_parse<T: Default + Parse + Token>(&self) -> Result<Option<T>>
Tries to parse T
as the next Token
.
Doesn’t move ParseBuffer
’s cursor if there is no T
.
Errors
If T
fails to be parsed.
sourcefn is_next<T: Default + Token>(&self) -> bool
fn is_next<T: Default + Token>(&self) -> bool
Checks whether the next Token
is T
.
Doesn’t move ParseBuffer
’s cursor.
sourcefn parse_any_ident(&self) -> Result<Ident>
fn parse_any_ident(&self) -> Result<Ident>
Parses the next Token
as syn::Ident
allowing Rust keywords,
while default Parse
implementation for syn::Ident
disallows
them.
Always moves ParseBuffer
’s cursor.
Errors
If syn::Ident
fails to be parsed.
sourcefn parse_wrapped_and_punctuated<T, W, P>(&self) -> Result<Punctuated<T, P>>where
T: Parse,
W: Default + Token + AcceptedWrapper + 'static,
P: Default + Parse + Token,
fn parse_wrapped_and_punctuated<T, W, P>(&self) -> Result<Punctuated<T, P>>where T: Parse, W: Default + Token + AcceptedWrapper + 'static, P: Default + Parse + Token,
Parses the wrapped (in a wrapper W
) Token
s as T
Punctuated
with a P
separator.
Always moves ParseBuffer
’s cursor.
Errors
If parsing Punctuated
T
wrapped into W
fails.
sourcefn parse_maybe_wrapped_and_punctuated<T, W, P>(
&self
) -> Result<Punctuated<T, P>>where
T: Parse,
W: Default + Token + AcceptedWrapper + 'static,
P: Default + Parse + Token,
fn parse_maybe_wrapped_and_punctuated<T, W, P>( &self ) -> Result<Punctuated<T, P>>where T: Parse, W: Default + Token + AcceptedWrapper + 'static, P: Default + Parse + Token,
Checks whether the next Token
is a wrapper W
and if yes, then
parses the wrapped Token
s as T
Punctuated
with a P
separator. Otherwise, parses just T
.
Always moves ParseBuffer
’s cursor.
Errors
If either parsing Punctuated
T
wrapped into W
, or parsing just
T
, fails.
sourcefn parse_eq_or_wrapped_and_punctuated<T, W, P>(
&self
) -> Result<Punctuated<T, P>>where
T: Parse,
W: Default + Token + AcceptedWrapper + 'static,
P: Default + Parse + Token,
fn parse_eq_or_wrapped_and_punctuated<T, W, P>( &self ) -> Result<Punctuated<T, P>>where T: Parse, W: Default + Token + AcceptedWrapper + 'static, P: Default + Parse + Token,
Checks whether the next Token
is a wrapper W
and if yes, then
parses the wrapped Token
s as T
Punctuated
with a P
separator. Otherwise, parses just T
following the token::Eq
.
Always moves ParseBuffer
’s cursor.
Errors
If either parsing Punctuated
T
wrapped into W
, or parsing just
T
following the token::Eq
, fails.
Provided Methods§
sourcefn skip_any_ident(&self) -> Result<()>
fn skip_any_ident(&self) -> Result<()>
Parses the next Token
as syn::Ident
allowing Rust keywords,
while default Parse
implementation for syn::Ident
disallows
them. Drops the parsed Token
in-place.
Always moves ParseBuffer
’s cursor.
Errors
If syn::Ident
fails to be parsed.