pub struct Eof;
Expand description
Verifies that parsing reached the end of the input (i.e., the end of the parse stream at the current level of nesting). Useful for ensuring that an input or a group is fully parsed by preceding types.
Consumes no tokens when parsed, produces no tokens when printed.
// an empty string / token stream should trivially parse as `Eof`
let _: Eof = "".parse()?;
// so should an all-whitespace one
let _: Eof = "\r\n ".parse()?;
#[derive(PartialEq, Eq, Debug, Parse)]
struct BoolAtEnd {
value: LitBool,
eof: Eof,
}
#[derive(PartialEq, Eq, Debug, Parse)]
enum IntOrBoolAtEnd {
Bool(BoolAtEnd),
Int(LitInt),
}
let actual: Punctuated<IntOrBoolAtEnd, Comma> = "2, 46, 802, false".parse()?;
let actual: Vec<_> = actual.into_iter().collect();
let expected = [
IntOrBoolAtEnd::Int(LitInt::from(2)),
IntOrBoolAtEnd::Int(LitInt::from(46)),
IntOrBoolAtEnd::Int(LitInt::from(802)),
IntOrBoolAtEnd::Bool(BoolAtEnd {
value: LitBool::from(false),
eof: Eof,
}),
];
assert_eq!(actual, expected);
let bad: Result<Punctuated<IntOrBoolAtEnd, Comma>> = "2, 46, false, 802".parse();
assert!(bad.is_err());
Implementations
Trait Implementations
sourceimpl Ord for Eof
impl Ord for Eof
sourceimpl PartialOrd<Eof> for Eof
impl PartialOrd<Eof> for Eof
sourcefn partial_cmp(&self, other: &Eof) -> Option<Ordering>
fn partial_cmp(&self, other: &Eof) -> Option<Ordering>
This method returns an ordering between self
and other
values if one exists. Read more
1.0.0 · sourcefn lt(&self, other: &Rhs) -> bool
fn lt(&self, other: &Rhs) -> bool
This method tests less than (for self
and other
) and is used by the <
operator. Read more
1.0.0 · sourcefn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
sourceimpl ToTokens for Eof
impl ToTokens for Eof
sourcefn to_tokens(&self, _tokens: &mut TokenStream)
fn to_tokens(&self, _tokens: &mut TokenStream)
Write self
to the given TokenStream
. Read more
sourcefn to_token_stream(&self) -> TokenStream
fn to_token_stream(&self) -> TokenStream
Convert self
directly into a TokenStream
object. Read more
sourcefn into_token_stream(self) -> TokenStream
fn into_token_stream(self) -> TokenStream
Convert self
directly into a TokenStream
object. Read more
impl Copy for Eof
impl Eq for Eof
impl StructuralEq for Eof
impl StructuralPartialEq for Eof
Auto Trait Implementations
impl RefUnwindSafe for Eof
impl Send for Eof
impl Sync for Eof
impl Unpin for Eof
impl UnwindSafe for Eof
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> Spanned for T where
T: Spanned + ?Sized,
impl<T> Spanned for T where
T: Spanned + ?Sized,
sourcefn span(&self) -> Span
fn span(&self) -> Span
Returns a Span
covering the complete contents of this syntax tree
node, or Span::call_site()
if this node is empty. Read more