pipe_chain/
tag.rs

1//! Input consumers
2
3use crate::{Incomplete, Pipe};
4use fatal_error::FatalError;
5use std::error::Error as StdError;
6
7/// Helper trait to recognize a tag
8pub trait Tag<T, E> {
9    /// Extracted tag
10    type Output;
11
12    /// remove self from the begining of `input`
13    fn strip_from(&self, input: T) -> Result<(T, (Self::Output,)), E>;
14}
15
16/// recognize the given tag at the begining of input
17/// 
18/// 
19pub fn tag<E, I, T: Tag<I, E>>(tag: T) -> impl Pipe<I, (T::Output,), E>
20where
21    E: StdError,
22    Incomplete: Into<E>,
23{
24    move |i: I| tag.strip_from(i).map_err(FatalError::Error)
25}