use crate::{
collect::{
self,
OwnedCollect,
},
stream::{
Arguments,
Error,
Stream,
},
value::Value,
};
pub struct OwnedStream<S>(OwnedCollect<collect::Default<S>>);
impl<S> OwnedStream<S>
where
S: Stream,
{
#[inline]
pub fn begin(stream: S) -> Result<Self, Error> {
Ok(OwnedStream(OwnedCollect::begin(collect::Default(stream))?))
}
#[inline]
pub fn end(self) -> Result<S, Error> {
Ok(self.0.end()?.0)
}
#[inline]
pub fn any(&mut self, v: impl Value) -> Result<(), Error> {
self.0.any(v)
}
#[inline]
pub fn fmt(&mut self, f: Arguments) -> Result<(), Error> {
self.0.fmt(f)
}
#[inline]
pub fn i64(&mut self, v: i64) -> Result<(), Error> {
self.0.i64(v)
}
#[inline]
pub fn u64(&mut self, v: u64) -> Result<(), Error> {
self.0.u64(v)
}
#[inline]
pub fn i128(&mut self, v: i128) -> Result<(), Error> {
self.0.i128(v)
}
#[inline]
pub fn u128(&mut self, v: u128) -> Result<(), Error> {
self.0.u128(v)
}
#[inline]
pub fn f64(&mut self, v: f64) -> Result<(), Error> {
self.0.f64(v)
}
#[inline]
pub fn bool(&mut self, v: bool) -> Result<(), Error> {
self.0.bool(v)
}
#[inline]
pub fn char(&mut self, v: char) -> Result<(), Error> {
self.0.char(v)
}
#[inline]
pub fn str(&mut self, v: &str) -> Result<(), Error> {
self.0.str(v)
}
#[inline]
pub fn none(&mut self) -> Result<(), Error> {
self.0.none()
}
#[inline]
pub fn map_begin(&mut self, len: Option<usize>) -> Result<(), Error> {
self.0.map_begin(len)
}
#[inline]
pub fn map_key(&mut self, k: impl Value) -> Result<(), Error> {
self.0.map_key(k)
}
#[inline]
pub fn map_value(&mut self, v: impl Value) -> Result<(), Error> {
self.0.map_value(v)
}
#[inline]
pub fn map_end(&mut self) -> Result<(), Error> {
self.0.map_end()
}
#[inline]
pub fn seq_begin(&mut self, len: Option<usize>) -> Result<(), Error> {
self.0.seq_begin(len)
}
#[inline]
pub fn seq_elem(&mut self, v: impl Value) -> Result<(), Error> {
self.0.seq_elem(v)
}
#[inline]
pub fn seq_end(&mut self) -> Result<(), Error> {
self.0.seq_end()
}
}
impl<S> OwnedStream<S>
where
S: Stream,
{
#[inline]
pub fn map_key_begin(&mut self) -> Result<&mut Self, Error> {
self.0.map_key_begin()?;
Ok(self)
}
#[inline]
pub fn map_value_begin(&mut self) -> Result<&mut Self, Error> {
self.0.map_value_begin()?;
Ok(self)
}
#[inline]
pub fn seq_elem_begin(&mut self) -> Result<&mut Self, Error> {
self.0.seq_elem_begin()?;
Ok(self)
}
}