use crate::Error; #[derive(Debug)] pub struct Endable { inner: T, ended: bool, } impl Endable { pub fn new(inner: T) -> Self { Self { inner, ended: false, } } pub fn end(&mut self) { self.ended = true; } pub fn into_inner(self) -> T { self.inner } #[inline(always)] pub fn try_as_mut(&mut self) -> Result<&mut T, Error> { if self.ended { Err(Error::RootElementEnded) } else { Ok(&mut self.inner) } } pub fn ignore_end(&mut self) -> &mut T { &mut self.inner } }