#[derive(Clone, Copy, Debug, PartialEq)]
#[cfg_attr(feature = "extra-traits", derive(PartialOrd, Eq, Ord, Hash))]
pub struct Indented<T> {
pub indent: T,
pub data: T,
}
impl<'a> Indented<&'a str> {
#[inline]
pub fn new(s: &'a str) -> Self {
let (indent, data) = s.split_at(
s.chars()
.take_while(|x| x.is_whitespace())
.map(|x| x.len_utf8())
.sum(),
);
Indented { indent, data }
}
}
pub trait IntoUnindented {
type Output;
fn into_unindented(self) -> Self::Output;
}
impl<'ast, T: 'ast> IntoUnindented for &'ast Indented<T> {
type Output = &'ast T;
#[inline]
fn into_unindented(self) -> &'ast T {
&self.data
}
}
impl<'ast, T: 'ast> IntoUnindented for &'ast crate::Block<T>
where
&'ast T: IntoUnindented,
{
type Output = crate::View<'ast, T, fn(&'ast T) -> <&'ast T as IntoUnindented>::Output>;
#[inline]
fn into_unindented(self) -> Self::Output {
crate::View::new(self, <&'ast T>::into_unindented)
}
}
impl<'ast, T, F, O> IntoUnindented for crate::View<'ast, T, F>
where
T: 'ast,
F: crate::view::ViewFn<&'ast T, Output = O>,
O: IntoUnindented + 'ast,
{
type Output = crate::View<'ast, T, crate::view::MapViewFn<F, fn(F::Output) -> O::Output>>;
#[inline]
fn into_unindented(self) -> Self::Output {
self.map(O::into_unindented)
}
}