Remove IOResult in favour of std::io::Result
This commit is contained in:
parent
da08189dd4
commit
7e76503779
|
@ -3,7 +3,6 @@ pub use lazy_static::lazy_static;
|
|||
use preserves::value::ArcValue;
|
||||
use preserves::value::Domain;
|
||||
use preserves::value::Embeddable;
|
||||
use preserves::value::IOResult;
|
||||
use preserves::value::IOValue;
|
||||
use preserves::value::NestedValue;
|
||||
use preserves::value::NoEmbeddedDomainCodec;
|
||||
|
@ -11,9 +10,10 @@ use preserves::value::Value;
|
|||
|
||||
use std::convert::From;
|
||||
use std::convert::TryFrom;
|
||||
use std::io;
|
||||
use std::sync::Arc;
|
||||
|
||||
pub fn decode_lit<D: Embeddable, N: NestedValue<D>>(bs: &[u8]) -> IOResult<N> {
|
||||
pub fn decode_lit<D: Embeddable, N: NestedValue<D>>(bs: &[u8]) -> io::Result<N> {
|
||||
preserves::value::packed::from_bytes(bs, NoEmbeddedDomainCodec)
|
||||
}
|
||||
|
||||
|
|
|
@ -7,6 +7,7 @@ pub mod value;
|
|||
|
||||
#[cfg(test)]
|
||||
mod dom {
|
||||
use std::io;
|
||||
use super::value::*;
|
||||
|
||||
#[derive(Debug, Hash, Clone, Ord, PartialEq, Eq, PartialOrd)]
|
||||
|
@ -17,7 +18,7 @@ mod dom {
|
|||
|
||||
impl Domain for Dom {}
|
||||
|
||||
fn dom_as_preserves(v: &Dom) -> IOResult<UnwrappedIOValue> {
|
||||
fn dom_as_preserves(v: &Dom) -> io::Result<UnwrappedIOValue> {
|
||||
Ok(match v {
|
||||
Dom::One => Value::ByteString(vec![255, 255, 255, 255]),
|
||||
Dom::Two => Value::symbol(&format!("Dom::{:?}", v)),
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
use std::io;
|
||||
|
||||
use super::BinarySource;
|
||||
use super::Embeddable;
|
||||
use super::IOResult;
|
||||
use super::IOValue;
|
||||
use super::Reader;
|
||||
use super::Writer;
|
||||
|
@ -11,7 +12,7 @@ pub trait DomainDecode<D: Embeddable> {
|
|||
&mut self,
|
||||
src: &'src mut S,
|
||||
read_annotations: bool,
|
||||
) -> IOResult<D>;
|
||||
) -> io::Result<D>;
|
||||
}
|
||||
|
||||
pub trait DomainEncode<D: Embeddable> {
|
||||
|
@ -19,7 +20,7 @@ pub trait DomainEncode<D: Embeddable> {
|
|||
&mut self,
|
||||
w: &mut W,
|
||||
d: &D,
|
||||
) -> IOResult<()>;
|
||||
) -> io::Result<()>;
|
||||
}
|
||||
|
||||
pub struct IOValueDomainCodec;
|
||||
|
@ -29,7 +30,7 @@ impl DomainDecode<IOValue> for IOValueDomainCodec {
|
|||
&mut self,
|
||||
src: &'src mut S,
|
||||
read_annotations: bool,
|
||||
) -> IOResult<IOValue> {
|
||||
) -> io::Result<IOValue> {
|
||||
PackedReader::new(src, IOValueDomainCodec).demand_next(read_annotations)
|
||||
}
|
||||
}
|
||||
|
@ -39,7 +40,7 @@ impl DomainEncode<IOValue> for IOValueDomainCodec {
|
|||
&mut self,
|
||||
w: &mut W,
|
||||
d: &IOValue,
|
||||
) -> IOResult<()> {
|
||||
) -> io::Result<()> {
|
||||
w.write(self, d)
|
||||
}
|
||||
}
|
||||
|
@ -51,7 +52,7 @@ impl<D: Embeddable> DomainDecode<D> for NoEmbeddedDomainCodec {
|
|||
&mut self,
|
||||
_src: &'src mut S,
|
||||
_read_annotations: bool,
|
||||
) -> IOResult<D> {
|
||||
) -> io::Result<D> {
|
||||
Err(std::io::Error::new(std::io::ErrorKind::Unsupported, "Embedded values not supported here"))
|
||||
}
|
||||
}
|
||||
|
@ -61,7 +62,7 @@ impl<D: Embeddable> DomainEncode<D> for NoEmbeddedDomainCodec {
|
|||
&mut self,
|
||||
_w: &mut W,
|
||||
_d: &D,
|
||||
) -> IOResult<()> {
|
||||
) -> io::Result<()> {
|
||||
Err(std::io::Error::new(std::io::ErrorKind::Unsupported, "Embedded values not supported here"))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -40,8 +40,6 @@ pub use ser::Serializer;
|
|||
pub use ser::to_value;
|
||||
pub use writer::Writer;
|
||||
|
||||
pub type IOResult<T> = std::result::Result<T, std::io::Error>;
|
||||
|
||||
pub fn invert_map<A, B>(m: &Map<A, B>) -> Map<B, A>
|
||||
where A: Clone, B: Clone + Ord
|
||||
{
|
||||
|
|
|
@ -5,26 +5,28 @@ pub mod writer;
|
|||
pub use reader::PackedReader;
|
||||
pub use writer::PackedWriter;
|
||||
|
||||
use super::{BinarySource, DomainDecode, Embeddable, IOResult, IOValue, IOValueDomainCodec, NestedValue, Reader};
|
||||
use std::io;
|
||||
|
||||
use super::{BinarySource, DomainDecode, Embeddable, IOValue, IOValueDomainCodec, NestedValue, Reader};
|
||||
|
||||
pub fn from_bytes<D: Embeddable, N: NestedValue<D>, Dec: DomainDecode<D>>(
|
||||
bs: &[u8],
|
||||
decode_embedded: Dec,
|
||||
) -> IOResult<N> {
|
||||
) -> io::Result<N> {
|
||||
super::BytesBinarySource::new(bs).packed(decode_embedded).demand_next(false)
|
||||
}
|
||||
|
||||
pub fn iovalue_from_bytes(bs: &[u8]) -> IOResult<IOValue> {
|
||||
pub fn iovalue_from_bytes(bs: &[u8]) -> io::Result<IOValue> {
|
||||
from_bytes(bs, IOValueDomainCodec)
|
||||
}
|
||||
|
||||
pub fn annotated_from_bytes<D: Embeddable, N: NestedValue<D>, Dec: DomainDecode<D>>(
|
||||
bs: &[u8],
|
||||
decode_embedded: Dec,
|
||||
) -> IOResult<N> {
|
||||
) -> io::Result<N> {
|
||||
super::BytesBinarySource::new(bs).packed(decode_embedded).demand_next(true)
|
||||
}
|
||||
|
||||
pub fn annotated_iovalue_from_bytes(bs: &[u8]) -> IOResult<IOValue> {
|
||||
pub fn annotated_iovalue_from_bytes(bs: &[u8]) -> io::Result<IOValue> {
|
||||
annotated_from_bytes(bs, IOValueDomainCodec)
|
||||
}
|
||||
|
|
|
@ -6,13 +6,13 @@ use num::traits::cast::{FromPrimitive, ToPrimitive};
|
|||
use std::borrow::Cow;
|
||||
use std::convert::TryFrom;
|
||||
use std::convert::TryInto;
|
||||
use std::io;
|
||||
use std::marker::PhantomData;
|
||||
|
||||
use super::constants::Tag;
|
||||
use super::super::{
|
||||
DomainDecode,
|
||||
Embeddable,
|
||||
IOResult,
|
||||
Map,
|
||||
NestedValue,
|
||||
Record,
|
||||
|
@ -39,16 +39,16 @@ impl<'de, 'src, D: Embeddable, N: NestedValue<D>, Dec: DomainDecode<D>, S: Binar
|
|||
BinarySource<'de>
|
||||
for PackedReader<'de, 'src, D, N, Dec, S>
|
||||
{
|
||||
fn skip(&mut self) -> IOResult<()> {
|
||||
fn skip(&mut self) -> io::Result<()> {
|
||||
self.source.skip()
|
||||
}
|
||||
fn peek(&mut self) -> IOResult<u8> {
|
||||
fn peek(&mut self) -> io::Result<u8> {
|
||||
self.source.peek()
|
||||
}
|
||||
fn readbytes(&mut self, count: usize) -> IOResult<Cow<'de, [u8]>> {
|
||||
fn readbytes(&mut self, count: usize) -> io::Result<Cow<'de, [u8]>> {
|
||||
self.source.readbytes(count)
|
||||
}
|
||||
fn readbytes_into(&mut self, bs: &mut [u8]) -> IOResult<()> {
|
||||
fn readbytes_into(&mut self, bs: &mut [u8]) -> io::Result<()> {
|
||||
self.source.readbytes_into(bs)
|
||||
}
|
||||
}
|
||||
|
@ -62,7 +62,7 @@ impl<'de, 'src, D: Embeddable, N: NestedValue<D>, Dec: DomainDecode<D>, S: Binar
|
|||
PackedReader { source, decode_embedded, phantom: PhantomData }
|
||||
}
|
||||
|
||||
fn read(&mut self) -> IOResult<u8> {
|
||||
fn read(&mut self) -> io::Result<u8> {
|
||||
let v = self.peek()?;
|
||||
self.skip()?;
|
||||
Ok(v)
|
||||
|
@ -75,7 +75,7 @@ impl<'de, 'src, D: Embeddable, N: NestedValue<D>, Dec: DomainDecode<D>, S: Binar
|
|||
}
|
||||
}
|
||||
|
||||
fn varint(&mut self) -> IOResult<usize> {
|
||||
fn varint(&mut self) -> io::Result<usize> {
|
||||
let mut shift = 0;
|
||||
let mut acc: usize = 0;
|
||||
loop {
|
||||
|
@ -86,7 +86,7 @@ impl<'de, 'src, D: Embeddable, N: NestedValue<D>, Dec: DomainDecode<D>, S: Binar
|
|||
}
|
||||
}
|
||||
|
||||
fn peekend(&mut self) -> IOResult<bool> {
|
||||
fn peekend(&mut self) -> io::Result<bool> {
|
||||
if self.peek()? == Tag::End.into() {
|
||||
self.skip()?;
|
||||
Ok(true)
|
||||
|
@ -129,7 +129,7 @@ impl<'de, 'src, D: Embeddable, N: NestedValue<D>, Dec: DomainDecode<D>, S: Binar
|
|||
}
|
||||
}
|
||||
|
||||
fn read_signed_integer(&mut self, count: usize) -> IOResult<SignedInteger> {
|
||||
fn read_signed_integer(&mut self, count: usize) -> io::Result<SignedInteger> {
|
||||
if count == 0 {
|
||||
return Ok(SignedInteger::from(0_i128));
|
||||
}
|
||||
|
@ -228,7 +228,7 @@ impl<'de, 'src, D: Embeddable, N: NestedValue<D>, Dec: DomainDecode<D>, S: Binar
|
|||
Reader<'de, D, N>
|
||||
for PackedReader<'de, 'src, D, N, Dec, S>
|
||||
{
|
||||
fn next(&mut self, read_annotations: bool) -> IOResult<Option<N>> {
|
||||
fn next(&mut self, read_annotations: bool) -> io::Result<Option<N>> {
|
||||
match self.peek() {
|
||||
Err(e) if is_eof_io_error(&e) => return Ok(None),
|
||||
Err(e) => return Err(e),
|
||||
|
@ -296,7 +296,7 @@ impl<'de, 'src, D: Embeddable, N: NestedValue<D>, Dec: DomainDecode<D>, S: Binar
|
|||
}
|
||||
Tag::Record => {
|
||||
let iter = DelimitedStream { reader: self.configured(read_annotations) };
|
||||
let vs = iter.collect::<IOResult<Vec<N>>>()?;
|
||||
let vs = iter.collect::<io::Result<Vec<N>>>()?;
|
||||
if vs.is_empty() {
|
||||
return Err(io_syntax_error("Too few elements in encoded record"))
|
||||
}
|
||||
|
@ -304,7 +304,7 @@ impl<'de, 'src, D: Embeddable, N: NestedValue<D>, Dec: DomainDecode<D>, S: Binar
|
|||
}
|
||||
Tag::Sequence => {
|
||||
let iter = DelimitedStream { reader: self.configured(read_annotations) };
|
||||
let vs = iter.collect::<IOResult<Vec<N>>>()?;
|
||||
let vs = iter.collect::<io::Result<Vec<N>>>()?;
|
||||
Value::Sequence(vs).wrap()
|
||||
}
|
||||
Tag::Set => {
|
||||
|
@ -456,7 +456,7 @@ impl<'a, 'de, 'src, D: Embeddable, N: NestedValue<D>, Dec: DomainDecode<D>, S: B
|
|||
Iterator
|
||||
for DelimitedStream<'a, 'de, 'src, D, N, Dec, S>
|
||||
{
|
||||
type Item = IOResult<N>;
|
||||
type Item = io::Result<N>;
|
||||
fn next(&mut self) -> Option<Self::Item> {
|
||||
match self.reader.reader.peekend() {
|
||||
Err(e) => Some(Err(e)),
|
||||
|
@ -466,7 +466,7 @@ impl<'a, 'de, 'src, D: Embeddable, N: NestedValue<D>, Dec: DomainDecode<D>, S: B
|
|||
}
|
||||
}
|
||||
|
||||
fn decodestr(cow: Cow<'_, [u8]>) -> IOResult<Cow<'_, str>> {
|
||||
fn decodestr(cow: Cow<'_, [u8]>) -> io::Result<Cow<'_, str>> {
|
||||
match cow {
|
||||
Cow::Borrowed(bs) =>
|
||||
Ok(Cow::Borrowed(std::str::from_utf8(bs).map_err(|_| io_syntax_error("Invalid UTF-8"))?)),
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
use num::bigint::BigInt;
|
||||
use num::cast::ToPrimitive;
|
||||
use std::convert::TryInto;
|
||||
use std::io;
|
||||
use std::mem;
|
||||
use std::ops::{Deref, DerefMut};
|
||||
use super::constants::Tag;
|
||||
|
@ -8,7 +9,6 @@ use super::super::DomainEncode;
|
|||
use super::super::Embeddable;
|
||||
use super::super::IOValue;
|
||||
use super::super::IOValueDomainCodec;
|
||||
use super::super::IOResult;
|
||||
use super::super::NestedValue;
|
||||
|
||||
use super::super::writer::{Writer, AnnotationWriter, CompoundWriter, varint};
|
||||
|
@ -78,7 +78,7 @@ impl PackedWriter<Vec<u8>> {
|
|||
pub fn encode<D: Embeddable, N: NestedValue<D>, Enc: DomainEncode<D>>(
|
||||
enc: &mut Enc,
|
||||
v: &N,
|
||||
) -> IOResult<Vec<u8>> {
|
||||
) -> io::Result<Vec<u8>> {
|
||||
let mut buf: Vec<u8> = Vec::new();
|
||||
let w = &mut PackedWriter::new(&mut buf);
|
||||
w.write(enc, v)?;
|
||||
|
@ -99,18 +99,18 @@ impl<W: std::io::Write> PackedWriter<W> {
|
|||
self.0.deref_mut()
|
||||
}
|
||||
|
||||
pub fn write_byte(&mut self, b: u8) -> IOResult<()> {
|
||||
pub fn write_byte(&mut self, b: u8) -> io::Result<()> {
|
||||
self.w().write_all(&[b])
|
||||
}
|
||||
|
||||
pub fn write_medium_integer(&mut self, bs: &[u8]) -> IOResult<()> {
|
||||
pub fn write_medium_integer(&mut self, bs: &[u8]) -> io::Result<()> {
|
||||
let count: u8 = bs.len().try_into().unwrap();
|
||||
if !(1..=16).contains(&count) { panic!("Invalid medium_integer count: {}", count) }
|
||||
self.write_byte(Tag::MediumInteger(count).into())?;
|
||||
self.w().write_all(bs)
|
||||
}
|
||||
|
||||
pub fn write_atom(&mut self, tag: Tag, bs: &[u8]) -> IOResult<()> {
|
||||
pub fn write_atom(&mut self, tag: Tag, bs: &[u8]) -> io::Result<()> {
|
||||
self.write_byte(tag.into())?;
|
||||
varint(&mut self.w(), bs.len().try_into().unwrap())?;
|
||||
self.w().write_all(bs)
|
||||
|
@ -152,7 +152,7 @@ impl BinaryOrderWriter {
|
|||
self.0.last_mut().unwrap()
|
||||
}
|
||||
|
||||
fn finish<W: WriteWriter>(mut self, w: &mut W) -> IOResult<()> {
|
||||
fn finish<W: WriteWriter>(mut self, w: &mut W) -> io::Result<()> {
|
||||
if !self.buffer().is_empty() { panic!("Missing final delimit()"); }
|
||||
self.items_mut().pop();
|
||||
self.items_mut().sort();
|
||||
|
@ -165,51 +165,51 @@ impl BinaryOrderWriter {
|
|||
}
|
||||
|
||||
pub trait WriteWriter: Writer {
|
||||
fn write_raw_bytes(&mut self, v: &[u8]) -> IOResult<()>;
|
||||
fn write_tag(&mut self, tag: Tag) -> IOResult<()> {
|
||||
fn write_raw_bytes(&mut self, v: &[u8]) -> io::Result<()>;
|
||||
fn write_tag(&mut self, tag: Tag) -> io::Result<()> {
|
||||
self.write_raw_bytes(&[tag.into()])
|
||||
}
|
||||
}
|
||||
|
||||
impl<W: std::io::Write> WriteWriter for PackedWriter<W> {
|
||||
fn write_raw_bytes(&mut self, v: &[u8]) -> IOResult<()> {
|
||||
fn write_raw_bytes(&mut self, v: &[u8]) -> io::Result<()> {
|
||||
self.w().write_all(v)
|
||||
}
|
||||
}
|
||||
|
||||
impl WriteWriter for BinaryOrderWriter {
|
||||
fn write_raw_bytes(&mut self, v: &[u8]) -> IOResult<()> {
|
||||
fn write_raw_bytes(&mut self, v: &[u8]) -> io::Result<()> {
|
||||
use std::io::Write;
|
||||
self.buffer().write_all(v)
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: WriteWriter> AnnotationWriter for T {
|
||||
fn start_annotation(&mut self) -> IOResult<()> {
|
||||
fn start_annotation(&mut self) -> io::Result<()> {
|
||||
Ok(self.write_tag(Tag::Annotation)?)
|
||||
}
|
||||
|
||||
fn start_value(&mut self) -> IOResult<()> {
|
||||
fn start_value(&mut self) -> io::Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
impl<W: std::io::Write> CompoundWriter for PackedWriter<W> {
|
||||
fn extend(&mut self) -> IOResult<()> {
|
||||
fn extend(&mut self) -> io::Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn delimit(&mut self) -> IOResult<()> {
|
||||
fn delimit(&mut self) -> io::Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
impl CompoundWriter for BinaryOrderWriter {
|
||||
fn extend(&mut self) -> IOResult<()> {
|
||||
fn extend(&mut self) -> io::Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn delimit(&mut self) -> IOResult<()> {
|
||||
fn delimit(&mut self) -> io::Result<()> {
|
||||
self.items_mut().push(vec![]);
|
||||
Ok(())
|
||||
}
|
||||
|
@ -228,67 +228,67 @@ impl Writer for BinaryOrderWriter {
|
|||
type SetWriter = BinaryOrderWriter;
|
||||
type EmbeddedWriter = PackedWriter<Vec<u8>>;
|
||||
|
||||
binary_order_writer_method!(mut align(natural_chunksize: u64) -> IOResult<()>);
|
||||
binary_order_writer_method!(mut align(natural_chunksize: u64) -> io::Result<()>);
|
||||
|
||||
fn start_annotations(&mut self) -> IOResult<Self::AnnWriter> {
|
||||
fn start_annotations(&mut self) -> io::Result<Self::AnnWriter> {
|
||||
Ok(self.pop())
|
||||
}
|
||||
fn end_annotations(&mut self, ann: Self::AnnWriter) -> IOResult<()> {
|
||||
fn end_annotations(&mut self, ann: Self::AnnWriter) -> io::Result<()> {
|
||||
self.push(ann);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
binary_order_writer_method!(mut write_bool(v: bool) -> IOResult<()>);
|
||||
binary_order_writer_method!(mut write_bool(v: bool) -> io::Result<()>);
|
||||
|
||||
binary_order_writer_method!(mut write_f32(v: f32) -> IOResult<()>);
|
||||
binary_order_writer_method!(mut write_f64(v: f64) -> IOResult<()>);
|
||||
binary_order_writer_method!(mut write_f32(v: f32) -> io::Result<()>);
|
||||
binary_order_writer_method!(mut write_f64(v: f64) -> io::Result<()>);
|
||||
|
||||
binary_order_writer_method!(mut write_i8(v: i8) -> IOResult<()>);
|
||||
binary_order_writer_method!(mut write_u8(v: u8) -> IOResult<()>);
|
||||
binary_order_writer_method!(mut write_i16(v: i16) -> IOResult<()>);
|
||||
binary_order_writer_method!(mut write_u16(v: u16) -> IOResult<()>);
|
||||
binary_order_writer_method!(mut write_i32(v: i32) -> IOResult<()>);
|
||||
binary_order_writer_method!(mut write_u32(v: u32) -> IOResult<()>);
|
||||
binary_order_writer_method!(mut write_i64(v: i64) -> IOResult<()>);
|
||||
binary_order_writer_method!(mut write_u64(v: u64) -> IOResult<()>);
|
||||
binary_order_writer_method!(mut write_i128(v: i128) -> IOResult<()>);
|
||||
binary_order_writer_method!(mut write_u128(v: u128) -> IOResult<()>);
|
||||
binary_order_writer_method!(mut write_int(v: &BigInt) -> IOResult<()>);
|
||||
binary_order_writer_method!(mut write_i8(v: i8) -> io::Result<()>);
|
||||
binary_order_writer_method!(mut write_u8(v: u8) -> io::Result<()>);
|
||||
binary_order_writer_method!(mut write_i16(v: i16) -> io::Result<()>);
|
||||
binary_order_writer_method!(mut write_u16(v: u16) -> io::Result<()>);
|
||||
binary_order_writer_method!(mut write_i32(v: i32) -> io::Result<()>);
|
||||
binary_order_writer_method!(mut write_u32(v: u32) -> io::Result<()>);
|
||||
binary_order_writer_method!(mut write_i64(v: i64) -> io::Result<()>);
|
||||
binary_order_writer_method!(mut write_u64(v: u64) -> io::Result<()>);
|
||||
binary_order_writer_method!(mut write_i128(v: i128) -> io::Result<()>);
|
||||
binary_order_writer_method!(mut write_u128(v: u128) -> io::Result<()>);
|
||||
binary_order_writer_method!(mut write_int(v: &BigInt) -> io::Result<()>);
|
||||
|
||||
binary_order_writer_method!(mut write_string(v: &str) -> IOResult<()>);
|
||||
binary_order_writer_method!(mut write_bytes(v: &[u8]) -> IOResult<()>);
|
||||
binary_order_writer_method!(mut write_symbol(v: &str) -> IOResult<()>);
|
||||
binary_order_writer_method!(mut write_string(v: &str) -> io::Result<()>);
|
||||
binary_order_writer_method!(mut write_bytes(v: &[u8]) -> io::Result<()>);
|
||||
binary_order_writer_method!(mut write_symbol(v: &str) -> io::Result<()>);
|
||||
|
||||
fn start_record(&mut self, _field_count: Option<usize>) -> IOResult<Self::SeqWriter> {
|
||||
fn start_record(&mut self, _field_count: Option<usize>) -> io::Result<Self::SeqWriter> {
|
||||
self.write_tag(Tag::Record)?;
|
||||
Ok(self.pop())
|
||||
}
|
||||
fn start_sequence(&mut self, _item_count: Option<usize>) -> IOResult<Self::SeqWriter> {
|
||||
fn start_sequence(&mut self, _item_count: Option<usize>) -> io::Result<Self::SeqWriter> {
|
||||
self.write_tag(Tag::Sequence)?;
|
||||
Ok(self.pop())
|
||||
}
|
||||
fn end_seq(&mut self, seq: Self::SeqWriter) -> IOResult<()> {
|
||||
fn end_seq(&mut self, seq: Self::SeqWriter) -> io::Result<()> {
|
||||
self.push(seq);
|
||||
self.write_tag(Tag::End)
|
||||
}
|
||||
|
||||
fn start_set(&mut self, _item_count: Option<usize>) -> IOResult<Self::SetWriter> {
|
||||
fn start_set(&mut self, _item_count: Option<usize>) -> io::Result<Self::SetWriter> {
|
||||
self.write_tag(Tag::Set)?;
|
||||
Ok(BinaryOrderWriter::new())
|
||||
}
|
||||
fn start_dictionary(&mut self, _entry_count: Option<usize>) -> IOResult<Self::SetWriter> {
|
||||
fn start_dictionary(&mut self, _entry_count: Option<usize>) -> io::Result<Self::SetWriter> {
|
||||
self.write_tag(Tag::Dictionary)?;
|
||||
Ok(BinaryOrderWriter::new())
|
||||
}
|
||||
fn end_set(&mut self, set: Self::SetWriter) -> IOResult<()> {
|
||||
fn end_set(&mut self, set: Self::SetWriter) -> io::Result<()> {
|
||||
set.finish(self)
|
||||
}
|
||||
|
||||
fn start_embedded(&mut self) -> IOResult<Self::EmbeddedWriter> {
|
||||
fn start_embedded(&mut self) -> io::Result<Self::EmbeddedWriter> {
|
||||
self.write_tag(Tag::Embedded)?;
|
||||
Ok(self.pop())
|
||||
}
|
||||
fn end_embedded(&mut self, ptr: Self::EmbeddedWriter) -> IOResult<()> {
|
||||
fn end_embedded(&mut self, ptr: Self::EmbeddedWriter) -> io::Result<()> {
|
||||
self.push(ptr);
|
||||
Ok(())
|
||||
}
|
||||
|
@ -308,54 +308,54 @@ impl<W: std::io::Write> Writer for PackedWriter<W>
|
|||
type SetWriter = BinaryOrderWriter;
|
||||
type EmbeddedWriter = Self;
|
||||
|
||||
fn start_annotations(&mut self) -> IOResult<Self::AnnWriter> {
|
||||
fn start_annotations(&mut self) -> io::Result<Self::AnnWriter> {
|
||||
Ok(self.suspend())
|
||||
}
|
||||
|
||||
fn end_annotations(&mut self, ann: Self::AnnWriter) -> IOResult<()> {
|
||||
fn end_annotations(&mut self, ann: Self::AnnWriter) -> io::Result<()> {
|
||||
self.resume(ann);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn align(&mut self, _natural_chunksize: u64) -> IOResult<()> {
|
||||
fn align(&mut self, _natural_chunksize: u64) -> io::Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn write_bool(&mut self, v: bool) -> IOResult<()> {
|
||||
fn write_bool(&mut self, v: bool) -> io::Result<()> {
|
||||
self.write_tag(if v { Tag::True } else { Tag::False })
|
||||
}
|
||||
|
||||
fn write_f32(&mut self, v: f32) -> IOResult<()> {
|
||||
fn write_f32(&mut self, v: f32) -> io::Result<()> {
|
||||
self.write_tag(Tag::Float)?;
|
||||
self.write_raw_bytes(&u32::to_be_bytes(f32::to_bits(v)))
|
||||
}
|
||||
|
||||
fn write_f64(&mut self, v: f64) -> IOResult<()> {
|
||||
fn write_f64(&mut self, v: f64) -> io::Result<()> {
|
||||
self.write_tag(Tag::Double)?;
|
||||
self.write_raw_bytes(&u64::to_be_bytes(f64::to_bits(v)))
|
||||
}
|
||||
|
||||
fn write_i8(&mut self, v: i8) -> IOResult<()> {
|
||||
fn write_i8(&mut self, v: i8) -> io::Result<()> {
|
||||
if v >= -3 && v <= 12 { return self.write_tag(Tag::SmallInteger(v)) }
|
||||
self.write_medium_integer(&[v as u8])
|
||||
}
|
||||
|
||||
fn write_u8(&mut self, v: u8) -> IOResult<()> {
|
||||
fn write_u8(&mut self, v: u8) -> io::Result<()> {
|
||||
if let Ok(w) = v.try_into() { return self.write_i8(w) }
|
||||
self.write_medium_integer(&[0, v])
|
||||
}
|
||||
|
||||
fn write_i16(&mut self, v: i16) -> IOResult<()> {
|
||||
fn write_i16(&mut self, v: i16) -> io::Result<()> {
|
||||
if let Ok(w) = v.try_into() { return self.write_i8(w) }
|
||||
self.write_medium_integer(&[(v >> 8) as u8, (v & 255) as u8])
|
||||
}
|
||||
|
||||
fn write_u16(&mut self, v: u16) -> IOResult<()> {
|
||||
fn write_u16(&mut self, v: u16) -> io::Result<()> {
|
||||
if let Ok(w) = v.try_into() { return self.write_i16(w) }
|
||||
self.write_medium_integer(&[0, (v >> 8) as u8, (v & 255) as u8])
|
||||
}
|
||||
|
||||
fn write_i32(&mut self, v: i32) -> IOResult<()> {
|
||||
fn write_i32(&mut self, v: i32) -> io::Result<()> {
|
||||
if let Ok(w) = v.try_into() { return self.write_i16(w) }
|
||||
if fits_in_bytes!(v, 3) {
|
||||
return self.write_medium_integer(&[(v >> 16) as u8,
|
||||
|
@ -368,7 +368,7 @@ impl<W: std::io::Write> Writer for PackedWriter<W>
|
|||
(v & 255) as u8])
|
||||
}
|
||||
|
||||
fn write_u32(&mut self, v: u32) -> IOResult<()> {
|
||||
fn write_u32(&mut self, v: u32) -> io::Result<()> {
|
||||
if let Ok(w) = v.try_into() { return self.write_i32(w) }
|
||||
self.write_medium_integer(&[0,
|
||||
(v >> 24) as u8,
|
||||
|
@ -377,7 +377,7 @@ impl<W: std::io::Write> Writer for PackedWriter<W>
|
|||
(v & 255) as u8])
|
||||
}
|
||||
|
||||
fn write_i64(&mut self, v: i64) -> IOResult<()> {
|
||||
fn write_i64(&mut self, v: i64) -> io::Result<()> {
|
||||
if let Ok(w) = v.try_into() { return self.write_i32(w) }
|
||||
if fits_in_bytes!(v, 5) {
|
||||
return self.write_medium_integer(&[(v >> 32) as u8,
|
||||
|
@ -413,7 +413,7 @@ impl<W: std::io::Write> Writer for PackedWriter<W>
|
|||
(v & 255) as u8])
|
||||
}
|
||||
|
||||
fn write_u64(&mut self, v: u64) -> IOResult<()> {
|
||||
fn write_u64(&mut self, v: u64) -> io::Result<()> {
|
||||
if let Ok(w) = v.try_into() { return self.write_i64(w) }
|
||||
self.write_medium_integer(&[0,
|
||||
(v >> 56) as u8,
|
||||
|
@ -426,7 +426,7 @@ impl<W: std::io::Write> Writer for PackedWriter<W>
|
|||
(v & 255) as u8])
|
||||
}
|
||||
|
||||
fn write_i128(&mut self, v: i128) -> IOResult<()> {
|
||||
fn write_i128(&mut self, v: i128) -> io::Result<()> {
|
||||
if let Ok(w) = v.try_into() { return self.write_i64(w) }
|
||||
let bs: [u8; 16] = v.to_be_bytes();
|
||||
if fits_in_bytes!(v, 9) { return self.write_medium_integer(&bs[7..]); }
|
||||
|
@ -439,7 +439,7 @@ impl<W: std::io::Write> Writer for PackedWriter<W>
|
|||
self.write_medium_integer(&bs)
|
||||
}
|
||||
|
||||
fn write_u128(&mut self, v: u128) -> IOResult<()> {
|
||||
fn write_u128(&mut self, v: u128) -> io::Result<()> {
|
||||
if let Ok(w) = v.try_into() { return self.write_i128(w) }
|
||||
let bs: [u8; 16] = v.to_be_bytes();
|
||||
self.write_tag(Tag::SignedInteger)?;
|
||||
|
@ -448,7 +448,7 @@ impl<W: std::io::Write> Writer for PackedWriter<W>
|
|||
self.write_raw_bytes(&bs)
|
||||
}
|
||||
|
||||
fn write_int(&mut self, v: &BigInt) -> IOResult<()> {
|
||||
fn write_int(&mut self, v: &BigInt) -> io::Result<()> {
|
||||
match v.to_i8() {
|
||||
Some(n) => self.write_i8(n),
|
||||
None => {
|
||||
|
@ -460,53 +460,53 @@ impl<W: std::io::Write> Writer for PackedWriter<W>
|
|||
}
|
||||
}
|
||||
|
||||
fn write_string(&mut self, v: &str) -> IOResult<()> {
|
||||
fn write_string(&mut self, v: &str) -> io::Result<()> {
|
||||
self.write_atom(Tag::String, v.as_bytes())
|
||||
}
|
||||
|
||||
fn write_bytes(&mut self, v: &[u8]) -> IOResult<()> {
|
||||
fn write_bytes(&mut self, v: &[u8]) -> io::Result<()> {
|
||||
self.write_atom(Tag::ByteString, v)
|
||||
}
|
||||
|
||||
fn write_symbol(&mut self, v: &str) -> IOResult<()> {
|
||||
fn write_symbol(&mut self, v: &str) -> io::Result<()> {
|
||||
self.write_atom(Tag::Symbol, v.as_bytes())
|
||||
}
|
||||
|
||||
fn start_record(&mut self, _field_count: Option<usize>) -> IOResult<Self::SeqWriter> {
|
||||
fn start_record(&mut self, _field_count: Option<usize>) -> io::Result<Self::SeqWriter> {
|
||||
self.write_tag(Tag::Record)?;
|
||||
Ok(self.suspend())
|
||||
}
|
||||
|
||||
fn start_sequence(&mut self, _item_count: Option<usize>) -> IOResult<Self::SeqWriter> {
|
||||
fn start_sequence(&mut self, _item_count: Option<usize>) -> io::Result<Self::SeqWriter> {
|
||||
self.write_tag(Tag::Sequence)?;
|
||||
Ok(self.suspend())
|
||||
}
|
||||
|
||||
fn end_seq(&mut self, seq: Self::SeqWriter) -> IOResult<()> {
|
||||
fn end_seq(&mut self, seq: Self::SeqWriter) -> io::Result<()> {
|
||||
self.resume(seq);
|
||||
self.write_tag(Tag::End)
|
||||
}
|
||||
|
||||
fn start_set(&mut self, _item_count: Option<usize>) -> IOResult<Self::SetWriter> {
|
||||
fn start_set(&mut self, _item_count: Option<usize>) -> io::Result<Self::SetWriter> {
|
||||
self.write_tag(Tag::Set)?;
|
||||
Ok(BinaryOrderWriter::new())
|
||||
}
|
||||
|
||||
fn start_dictionary(&mut self, _entry_count: Option<usize>) -> IOResult<Self::SetWriter> {
|
||||
fn start_dictionary(&mut self, _entry_count: Option<usize>) -> io::Result<Self::SetWriter> {
|
||||
self.write_tag(Tag::Dictionary)?;
|
||||
Ok(BinaryOrderWriter::new())
|
||||
}
|
||||
|
||||
fn end_set(&mut self, set: Self::SetWriter) -> IOResult<()> {
|
||||
fn end_set(&mut self, set: Self::SetWriter) -> io::Result<()> {
|
||||
set.finish(self)
|
||||
}
|
||||
|
||||
fn start_embedded(&mut self) -> IOResult<Self::EmbeddedWriter> {
|
||||
fn start_embedded(&mut self) -> io::Result<Self::EmbeddedWriter> {
|
||||
self.write_tag(Tag::Embedded)?;
|
||||
Ok(self.suspend())
|
||||
}
|
||||
|
||||
fn end_embedded(&mut self, ann: Self::EmbeddedWriter) -> IOResult<()> {
|
||||
fn end_embedded(&mut self, ann: Self::EmbeddedWriter) -> io::Result<()> {
|
||||
self.resume(ann);
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
@ -1,15 +1,16 @@
|
|||
use crate::error::{self, ExpectedKind, Received, io_eof};
|
||||
|
||||
use std::borrow::Cow;
|
||||
use std::io;
|
||||
use std::io::Read;
|
||||
use std::marker::PhantomData;
|
||||
|
||||
use super::{DomainDecode, Embeddable, IOResult, IOValue, IOValueDomainCodec, NestedValue};
|
||||
use super::{DomainDecode, Embeddable, IOValue, IOValueDomainCodec, NestedValue};
|
||||
|
||||
pub type ReaderResult<T> = std::result::Result<T, error::Error>;
|
||||
|
||||
pub trait Reader<'de, D: Embeddable, N: NestedValue<D>> {
|
||||
fn next(&mut self, read_annotations: bool) -> IOResult<Option<N>>;
|
||||
fn next(&mut self, read_annotations: bool) -> io::Result<Option<N>>;
|
||||
fn open_record(&mut self, arity: Option<usize>) -> ReaderResult<()>;
|
||||
fn open_sequence_or_set(&mut self) -> ReaderResult<()>;
|
||||
fn open_sequence(&mut self) -> ReaderResult<()>;
|
||||
|
@ -21,13 +22,13 @@ pub trait Reader<'de, D: Embeddable, N: NestedValue<D>> {
|
|||
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
fn skip_value(&mut self) -> IOResult<()> {
|
||||
fn skip_value(&mut self) -> io::Result<()> {
|
||||
// TODO efficient skipping in specific impls of this trait
|
||||
let _ = self.demand_next(false)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn demand_next(&mut self, read_annotations: bool) -> IOResult<N> {
|
||||
fn demand_next(&mut self, read_annotations: bool) -> io::Result<N> {
|
||||
self.next(read_annotations)?.ok_or_else(io_eof)
|
||||
}
|
||||
|
||||
|
@ -121,7 +122,7 @@ impl<'r, 'de, D: Embeddable, N: NestedValue<D>, R: Reader<'de, D, N>>
|
|||
Reader<'de, D, N>
|
||||
for &'r mut R
|
||||
{
|
||||
fn next(&mut self, read_annotations: bool) -> IOResult<Option<N>> {
|
||||
fn next(&mut self, read_annotations: bool) -> io::Result<Option<N>> {
|
||||
(*self).next(read_annotations)
|
||||
}
|
||||
|
||||
|
@ -160,10 +161,10 @@ impl<'r, 'de, D: Embeddable, N: NestedValue<D>, R: Reader<'de, D, N>>
|
|||
|
||||
|
||||
pub trait BinarySource<'de>: Sized {
|
||||
fn skip(&mut self) -> IOResult<()>;
|
||||
fn peek(&mut self) -> IOResult<u8>;
|
||||
fn readbytes(&mut self, count: usize) -> IOResult<Cow<'de, [u8]>>;
|
||||
fn readbytes_into(&mut self, bs: &mut [u8]) -> IOResult<()>;
|
||||
fn skip(&mut self) -> io::Result<()>;
|
||||
fn peek(&mut self) -> io::Result<u8>;
|
||||
fn readbytes(&mut self, count: usize) -> io::Result<Cow<'de, [u8]>>;
|
||||
fn readbytes_into(&mut self, bs: &mut [u8]) -> io::Result<()>;
|
||||
|
||||
fn packed<D: Embeddable, N: NestedValue<D>, Dec: DomainDecode<D>>(
|
||||
&mut self,
|
||||
|
@ -191,13 +192,13 @@ impl<'a, R: Read> IOBinarySource<'a, R> {
|
|||
}
|
||||
|
||||
impl<'de, 'a, R: Read> BinarySource<'de> for IOBinarySource<'a, R> {
|
||||
fn skip(&mut self) -> IOResult<()> {
|
||||
fn skip(&mut self) -> io::Result<()> {
|
||||
if self.buf.is_none() { unreachable!(); }
|
||||
self.buf = None;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn peek(&mut self) -> IOResult<u8> {
|
||||
fn peek(&mut self) -> io::Result<u8> {
|
||||
match self.buf {
|
||||
Some(b) => Ok(b),
|
||||
None => {
|
||||
|
@ -214,14 +215,14 @@ impl<'de, 'a, R: Read> BinarySource<'de> for IOBinarySource<'a, R> {
|
|||
}
|
||||
}
|
||||
|
||||
fn readbytes(&mut self, count: usize) -> IOResult<Cow<'de, [u8]>> {
|
||||
fn readbytes(&mut self, count: usize) -> io::Result<Cow<'de, [u8]>> {
|
||||
if self.buf.is_some() { unreachable!(); }
|
||||
let mut bs = vec![0; count];
|
||||
self.read.read_exact(&mut bs)?;
|
||||
Ok(Cow::Owned(bs))
|
||||
}
|
||||
|
||||
fn readbytes_into(&mut self, bs: &mut [u8]) -> IOResult<()> {
|
||||
fn readbytes_into(&mut self, bs: &mut [u8]) -> io::Result<()> {
|
||||
if self.buf.is_some() { unreachable!(); }
|
||||
self.read.read_exact(bs)
|
||||
}
|
||||
|
@ -239,13 +240,13 @@ impl<'de> BytesBinarySource<'de> {
|
|||
}
|
||||
|
||||
impl<'de> BinarySource<'de> for BytesBinarySource<'de> {
|
||||
fn skip(&mut self) -> IOResult<()> {
|
||||
fn skip(&mut self) -> io::Result<()> {
|
||||
if self.index >= self.bytes.len() { unreachable!(); }
|
||||
self.index += 1;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn peek(&mut self) -> IOResult<u8> {
|
||||
fn peek(&mut self) -> io::Result<u8> {
|
||||
if self.index >= self.bytes.len() {
|
||||
Err(io_eof())
|
||||
} else {
|
||||
|
@ -253,7 +254,7 @@ impl<'de> BinarySource<'de> for BytesBinarySource<'de> {
|
|||
}
|
||||
}
|
||||
|
||||
fn readbytes(&mut self, count: usize) -> IOResult<Cow<'de, [u8]>> {
|
||||
fn readbytes(&mut self, count: usize) -> io::Result<Cow<'de, [u8]>> {
|
||||
if self.index + count > self.bytes.len() {
|
||||
Err(io_eof())
|
||||
} else {
|
||||
|
@ -263,7 +264,7 @@ impl<'de> BinarySource<'de> for BytesBinarySource<'de> {
|
|||
}
|
||||
}
|
||||
|
||||
fn readbytes_into(&mut self, bs: &mut [u8]) -> IOResult<()> {
|
||||
fn readbytes_into(&mut self, bs: &mut [u8]) -> io::Result<()> {
|
||||
let count = bs.len();
|
||||
if self.index + count > self.bytes.len() {
|
||||
Err(io_eof())
|
||||
|
@ -290,7 +291,7 @@ impl<'de, D: Embeddable, N: NestedValue<D>, R: Reader<'de, D, N>> ConfiguredRead
|
|||
self.read_annotations = read_annotations
|
||||
}
|
||||
|
||||
pub fn demand_next(&mut self) -> IOResult<N> {
|
||||
pub fn demand_next(&mut self) -> io::Result<N> {
|
||||
self.reader.demand_next(self.read_annotations)
|
||||
}
|
||||
}
|
||||
|
@ -299,7 +300,7 @@ impl<'de, D: Embeddable, N: NestedValue<D>, R: Reader<'de, D, N>>
|
|||
std::iter::Iterator
|
||||
for ConfiguredReader<'de, D, N, R>
|
||||
{
|
||||
type Item = IOResult<N>;
|
||||
type Item = io::Result<N>;
|
||||
fn next(&mut self) -> Option<Self::Item> {
|
||||
match self.reader.next(self.read_annotations) {
|
||||
Err(e) => Some(Err(e)),
|
||||
|
|
|
@ -1,17 +1,17 @@
|
|||
use num::bigint::BigInt;
|
||||
use std::io;
|
||||
use super::DomainEncode;
|
||||
use super::IOResult;
|
||||
use super::signed_integer::SignedIntegerRepr;
|
||||
use super::repr::{Embeddable, Value, NestedValue, Float, Double};
|
||||
|
||||
pub trait AnnotationWriter: Writer {
|
||||
fn start_annotation(&mut self) -> IOResult<()>;
|
||||
fn start_value(&mut self) -> IOResult<()>;
|
||||
fn start_annotation(&mut self) -> io::Result<()>;
|
||||
fn start_value(&mut self) -> io::Result<()>;
|
||||
}
|
||||
|
||||
pub trait CompoundWriter: Writer {
|
||||
fn extend(&mut self) -> IOResult<()>;
|
||||
fn delimit(&mut self) -> IOResult<()>;
|
||||
fn extend(&mut self) -> io::Result<()>;
|
||||
fn delimit(&mut self) -> io::Result<()>;
|
||||
}
|
||||
|
||||
pub trait Writer: Sized {
|
||||
|
@ -20,42 +20,42 @@ pub trait Writer: Sized {
|
|||
type SetWriter: CompoundWriter;
|
||||
type EmbeddedWriter: Writer;
|
||||
|
||||
fn align(&mut self, natural_chunksize: u64) -> IOResult<()>;
|
||||
fn align(&mut self, natural_chunksize: u64) -> io::Result<()>;
|
||||
|
||||
fn start_annotations(&mut self) -> IOResult<Self::AnnWriter>;
|
||||
fn end_annotations(&mut self, ann: Self::AnnWriter) -> IOResult<()>;
|
||||
fn start_annotations(&mut self) -> io::Result<Self::AnnWriter>;
|
||||
fn end_annotations(&mut self, ann: Self::AnnWriter) -> io::Result<()>;
|
||||
|
||||
fn write_bool(&mut self, v: bool) -> IOResult<()>;
|
||||
fn write_bool(&mut self, v: bool) -> io::Result<()>;
|
||||
|
||||
fn write_f32(&mut self, v: f32) -> IOResult<()>;
|
||||
fn write_f64(&mut self, v: f64) -> IOResult<()>;
|
||||
fn write_f32(&mut self, v: f32) -> io::Result<()>;
|
||||
fn write_f64(&mut self, v: f64) -> io::Result<()>;
|
||||
|
||||
fn write_i8(&mut self, v: i8) -> IOResult<()>;
|
||||
fn write_u8(&mut self, v: u8) -> IOResult<()>;
|
||||
fn write_i16(&mut self, v: i16) -> IOResult<()>;
|
||||
fn write_u16(&mut self, v: u16) -> IOResult<()>;
|
||||
fn write_i32(&mut self, v: i32) -> IOResult<()>;
|
||||
fn write_u32(&mut self, v: u32) -> IOResult<()>;
|
||||
fn write_i64(&mut self, v: i64) -> IOResult<()>;
|
||||
fn write_u64(&mut self, v: u64) -> IOResult<()>;
|
||||
fn write_i128(&mut self, v: i128) -> IOResult<()>;
|
||||
fn write_u128(&mut self, v: u128) -> IOResult<()>;
|
||||
fn write_int(&mut self, v: &BigInt) -> IOResult<()>;
|
||||
fn write_i8(&mut self, v: i8) -> io::Result<()>;
|
||||
fn write_u8(&mut self, v: u8) -> io::Result<()>;
|
||||
fn write_i16(&mut self, v: i16) -> io::Result<()>;
|
||||
fn write_u16(&mut self, v: u16) -> io::Result<()>;
|
||||
fn write_i32(&mut self, v: i32) -> io::Result<()>;
|
||||
fn write_u32(&mut self, v: u32) -> io::Result<()>;
|
||||
fn write_i64(&mut self, v: i64) -> io::Result<()>;
|
||||
fn write_u64(&mut self, v: u64) -> io::Result<()>;
|
||||
fn write_i128(&mut self, v: i128) -> io::Result<()>;
|
||||
fn write_u128(&mut self, v: u128) -> io::Result<()>;
|
||||
fn write_int(&mut self, v: &BigInt) -> io::Result<()>;
|
||||
|
||||
fn write_string(&mut self, v: &str) -> IOResult<()>;
|
||||
fn write_bytes(&mut self, v: &[u8]) -> IOResult<()>;
|
||||
fn write_symbol(&mut self, v: &str) -> IOResult<()>;
|
||||
fn write_string(&mut self, v: &str) -> io::Result<()>;
|
||||
fn write_bytes(&mut self, v: &[u8]) -> io::Result<()>;
|
||||
fn write_symbol(&mut self, v: &str) -> io::Result<()>;
|
||||
|
||||
fn start_record(&mut self, field_count: Option<usize>) -> IOResult<Self::SeqWriter>;
|
||||
fn start_sequence(&mut self, item_count: Option<usize>) -> IOResult<Self::SeqWriter>;
|
||||
fn end_seq(&mut self, seq: Self::SeqWriter) -> IOResult<()>;
|
||||
fn start_record(&mut self, field_count: Option<usize>) -> io::Result<Self::SeqWriter>;
|
||||
fn start_sequence(&mut self, item_count: Option<usize>) -> io::Result<Self::SeqWriter>;
|
||||
fn end_seq(&mut self, seq: Self::SeqWriter) -> io::Result<()>;
|
||||
|
||||
fn start_set(&mut self, item_count: Option<usize>) -> IOResult<Self::SetWriter>;
|
||||
fn start_dictionary(&mut self, entry_count: Option<usize>) -> IOResult<Self::SetWriter>;
|
||||
fn end_set(&mut self, set: Self::SetWriter) -> IOResult<()>;
|
||||
fn start_set(&mut self, item_count: Option<usize>) -> io::Result<Self::SetWriter>;
|
||||
fn start_dictionary(&mut self, entry_count: Option<usize>) -> io::Result<Self::SetWriter>;
|
||||
fn end_set(&mut self, set: Self::SetWriter) -> io::Result<()>;
|
||||
|
||||
fn start_embedded(&mut self) -> IOResult<Self::EmbeddedWriter>;
|
||||
fn end_embedded(&mut self, ptr: Self::EmbeddedWriter) -> IOResult<()>;
|
||||
fn start_embedded(&mut self) -> io::Result<Self::EmbeddedWriter>;
|
||||
fn end_embedded(&mut self, ptr: Self::EmbeddedWriter) -> io::Result<()>;
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
|
@ -63,7 +63,7 @@ pub trait Writer: Sized {
|
|||
&mut self,
|
||||
enc: &mut Enc,
|
||||
v: &N,
|
||||
) -> IOResult<()> {
|
||||
) -> io::Result<()> {
|
||||
match v.annotations().maybe_slice() {
|
||||
None => {
|
||||
self.write_value(enc, v.value())?;
|
||||
|
@ -86,7 +86,7 @@ pub trait Writer: Sized {
|
|||
&mut self,
|
||||
enc: &mut Enc,
|
||||
v: &Value<N, D>,
|
||||
) -> IOResult<()> {
|
||||
) -> io::Result<()> {
|
||||
match v {
|
||||
Value::Boolean(b) => self.write_bool(*b),
|
||||
Value::Float(Float(f)) => self.write_f32(*f),
|
||||
|
@ -148,7 +148,7 @@ pub trait Writer: Sized {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn varint<W: std::io::Write>(w: &mut W, mut v: u64) -> IOResult<usize> {
|
||||
pub fn varint<W: std::io::Write>(w: &mut W, mut v: u64) -> io::Result<usize> {
|
||||
let mut byte_count = 0;
|
||||
loop {
|
||||
byte_count += 1;
|
||||
|
|
Loading…
Reference in New Issue