binator/
core_atom.rs

1use core::fmt::{
2  Debug,
3  Display,
4  Formatter,
5};
6
7use crate::*;
8
9#[derive(Debug, Clone, PartialEq, Eq)]
10/// Core context used to implement context for basic type like u8
11pub enum CoreAtom<Stream, Error = <Stream as Streaming>::Error> {
12  /// Used when end of stream is reached.
13  EndOfStream {
14    /// The stream that returned end of stream.
15    stream: Stream,
16  },
17  /// Used when stream return an Error.
18  Error {
19    /// the error returned by the stream.
20    error: Error,
21  },
22}
23
24impl<Stream: Streaming> Display for CoreAtom<Stream>
25where
26  Stream: Debug,
27  Stream::Error: Debug,
28{
29  fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result {
30    match self {
31      Self::EndOfStream { .. } => write!(f, "End of stream"),
32      Self::Error { error } => write!(f, "The stream have encounter an error {:?}", error,),
33    }
34  }
35}