use crate::{
base::any,
Contexting,
CoreAtom,
Parse,
Parsed,
Streaming,
};
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct EndOfStreamAtom<Stream: Streaming, Item = <Stream as Streaming>::Item> {
pub item: Item,
pub stream: Stream,
}
#[cfg_attr(
feature = "tracing",
tracing::instrument(level = "trace", skip_all, ret(Display))
)]
pub fn end_of_stream<Stream, Context>(stream: Stream) -> Parsed<(), Stream, Context>
where
Stream: Streaming,
Context: Contexting<CoreAtom<Stream>>,
Context: Contexting<EndOfStreamAtom<Stream>>,
{
match any.parse(stream.clone()) {
Parsed::Success { token, stream } => Parsed::Failure(Context::new(EndOfStreamAtom {
item: token,
stream,
})),
Parsed::Failure(_context) => Parsed::Success { token: (), stream },
Parsed::Error(context) => Parsed::Error(context),
}
}