blob: 6d842f36250a02a9e744febf8a7eab7c3f60afb0 (
plain) (
tree)
|
|
use crate::Error;
#[derive(Debug)]
pub struct Endable<T> {
inner: T,
ended: bool,
}
impl<T> Endable<T> {
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
}
}
|