protocol-traits-plz 0.0.4

Protocol traits for the ParsePlz ecosystem
Documentation
use buffer_plz::Event;

use crate::frame::Frame;

/* Description:
 *      Trait to read a frame.
 *
 * Methods:
 *      try_next()
 *          Description : Process the event generated by IO to proceed with
 *                        the next step.
 *          Args        : Event
 *          Returns     : Self
 *          Errors      : StateError
 *
 *      is_ended()
 *          Description : Check if a frame has been read.
 *          Returns     : bool
 *
 *      try_into_frame()
 *          Description : Consumes the state machine and returns the frame.
 *          Returns     : T
 *          Errors      : FrameError
 *
 *  Implementation:
 *          OneOneState
 */

pub trait Step<T>
where
    T: Frame,
{
    type StateError;
    type FrameError;

    fn try_next(self, event: Event) -> Result<Self, Self::StateError>
    where
        Self: Sized;

    fn is_ended(&self) -> bool;

    fn try_into_frame(self) -> Result<T, Self::FrameError>;
}