use std::fmt::Debug;
use syn::parse::{Parse, ParseStream};
#[derive(Debug, Clone)]
pub struct Unit<T: Clone + Debug, N: Clone + Debug> {
pub parsed: T,
pub next: Option<N>,
}
pub type UnitResult<T, N> = syn::Result<Unit<T, N>>;
pub trait ParseUnit<N: Clone + Debug> {
fn parse_unit<T: Parse + Clone + Debug>(
&self,
input: ParseStream,
allow_empty_parsed: bool,
) -> UnitResult<T, N>;
}
pub trait MapParsed<T, R> {
type Output: Clone + Debug;
fn map_parsed<F>(self, f: F) -> Self::Output
where
F: FnOnce(T) -> R;
}
impl<T: Clone + Debug, R: Clone + Debug, N: Clone + Debug> MapParsed<T, R> for UnitResult<T, N> {
type Output = UnitResult<R, N>;
fn map_parsed<F>(self, f: F) -> Self::Output
where
F: FnOnce(T) -> R,
{
self.map(|Unit { parsed, next }| Unit {
parsed: f(parsed),
next,
})
}
}