`rec!` macro; access to `io::Write` inside `Writer`s
This commit is contained in:
parent
76ca8fe12b
commit
261395beaf
|
@ -268,6 +268,11 @@ impl Writer for BinaryOrderWriter {
|
|||
self.push(ptr);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
fn flush(&mut self) -> io::Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
macro_rules! fits_in_bytes {
|
||||
|
@ -522,4 +527,9 @@ impl<W: io::Write> Writer for PackedWriter<W>
|
|||
self.resume(ann);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
fn flush(&mut self) -> io::Result<()> {
|
||||
self.0.flush()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1533,3 +1533,24 @@ impl<D: Embeddable> NestedValue for DummyValue<D> {
|
|||
self.0.1
|
||||
}
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
// https://stackoverflow.com/questions/34304593/counting-length-of-repetition-in-macro/34324856
|
||||
#[macro_export]
|
||||
//#[allow(unused_macros)]
|
||||
macro_rules! count__ {
|
||||
() => (0usize);
|
||||
( $x:tt $($xs:tt)* ) => (1usize + $crate::count__!($($xs)*));
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! rec {
|
||||
( $label:expr $(, $item:expr)* ) => {
|
||||
{
|
||||
let mut r__ = $crate::value::Value::record($label, $crate::count__!($($item)*));
|
||||
$(r__.fields_vec_mut().push($item);)*
|
||||
r__.finish().wrap()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -121,6 +121,10 @@ impl<W: io::Write> TextWriter<W> {
|
|||
write!(self.w, " ")
|
||||
}
|
||||
}
|
||||
|
||||
pub fn borrow_write(&mut self) -> &mut W {
|
||||
&mut self.w
|
||||
}
|
||||
}
|
||||
|
||||
impl<W: io::Write> CompoundWriter for TextWriter<W> {
|
||||
|
@ -313,4 +317,8 @@ impl<W: io::Write> Writer for TextWriter<W> {
|
|||
self.resume(ptr);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn flush(&mut self) -> io::Result<()> {
|
||||
self.w.flush()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -56,6 +56,8 @@ pub trait Writer: Sized {
|
|||
fn start_embedded(&mut self) -> io::Result<Self::EmbeddedWriter>;
|
||||
fn end_embedded(&mut self, ptr: Self::EmbeddedWriter) -> io::Result<()>;
|
||||
|
||||
fn flush(&mut self) -> io::Result<()>;
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
fn write<N: NestedValue, Enc: DomainEncode<N::Embedded>>(
|
||||
|
|
Loading…
Reference in New Issue