|
@@ -3,14 +3,14 @@ use crate::*;
|
|
|
use std::{
|
|
use std::{
|
|
|
collections::HashMap,
|
|
collections::HashMap,
|
|
|
hash::Hash,
|
|
hash::Hash,
|
|
|
- io::{Error, ErrorKind, Read, Result, Write},
|
|
|
|
|
|
|
+ io::{Error, Read, Result, Write},
|
|
|
mem::size_of,
|
|
mem::size_of,
|
|
|
ops::Deref,
|
|
ops::Deref,
|
|
|
time::{Duration, SystemTime, UNIX_EPOCH}
|
|
time::{Duration, SystemTime, UNIX_EPOCH}
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
use arrayvec::ArrayVec;
|
|
use arrayvec::ArrayVec;
|
|
|
-use paste::paste;
|
|
|
|
|
|
|
+use pastey::paste;
|
|
|
|
|
|
|
|
macro_rules! impl_basic {
|
|
macro_rules! impl_basic {
|
|
|
($type:ty) => {
|
|
($type:ty) => {
|
|
@@ -108,7 +108,7 @@ impl Io for char {
|
|
|
fn read(r: &mut Reader) -> Result<Self> {
|
|
fn read(r: &mut Reader) -> Result<Self> {
|
|
|
use utf8_chars::BufReadCharsExt;
|
|
use utf8_chars::BufReadCharsExt;
|
|
|
r.read_char()?
|
|
r.read_char()?
|
|
|
- .ok_or_else(|| other("unexpected EOF"))
|
|
|
|
|
|
|
+ .ok_or_else(|| Error::other("unexpected EOF"))
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
fn write(&self, w: &mut Writer) -> Result<()> {
|
|
fn write(&self, w: &mut Writer) -> Result<()> {
|
|
@@ -129,12 +129,12 @@ impl Io for usize {
|
|
|
fn read(r: &mut Reader) -> Result<Self> {
|
|
fn read(r: &mut Reader) -> Result<Self> {
|
|
|
u64::read(r)?
|
|
u64::read(r)?
|
|
|
.try_into()
|
|
.try_into()
|
|
|
- .map_err(other)
|
|
|
|
|
|
|
+ .map_err(Error::other)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
fn write(&self, w: &mut Writer) -> Result<()> {
|
|
fn write(&self, w: &mut Writer) -> Result<()> {
|
|
|
u64::try_from(*self)
|
|
u64::try_from(*self)
|
|
|
- .map_err(other)?
|
|
|
|
|
|
|
+ .map_err(Error::other)?
|
|
|
.write(w)
|
|
.write(w)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -205,7 +205,7 @@ impl LenIo for String {
|
|
|
let mut bytes = vec![0; len as usize];
|
|
let mut bytes = vec![0; len as usize];
|
|
|
r.read_exact(&mut bytes)?;
|
|
r.read_exact(&mut bytes)?;
|
|
|
Self::from_utf8(bytes)
|
|
Self::from_utf8(bytes)
|
|
|
- .map_err(other)
|
|
|
|
|
|
|
+ .map_err(Error::other)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
fn write<L: Len>(&self, w: &mut Writer) -> Result<()> {
|
|
fn write<L: Len>(&self, w: &mut Writer) -> Result<()> {
|
|
@@ -290,7 +290,7 @@ impl LenIo for Duration {
|
|
|
|
|
|
|
|
fn write<L: Len>(&self, w: &mut Writer) -> Result<()> {
|
|
fn write<L: Len>(&self, w: &mut Writer) -> Result<()> {
|
|
|
let ms = u64::try_from(self.as_millis())
|
|
let ms = u64::try_from(self.as_millis())
|
|
|
- .map_err(other)?;
|
|
|
|
|
|
|
+ .map_err(Error::other)?;
|
|
|
L::try_from(ms)
|
|
L::try_from(ms)
|
|
|
.map_err(conversion)?
|
|
.map_err(conversion)?
|
|
|
.write(w)
|
|
.write(w)
|
|
@@ -312,9 +312,9 @@ impl Io for SystemTime {
|
|
|
|
|
|
|
|
fn write(&self, w: &mut Writer) -> Result<()> {
|
|
fn write(&self, w: &mut Writer) -> Result<()> {
|
|
|
u64::try_from(self.duration_since(UNIX_EPOCH)
|
|
u64::try_from(self.duration_since(UNIX_EPOCH)
|
|
|
- .map_err(other)
|
|
|
|
|
|
|
+ .map_err(Error::other)
|
|
|
.map(|offset| offset.as_millis())?)
|
|
.map(|offset| offset.as_millis())?)
|
|
|
- .map_err(other)?
|
|
|
|
|
|
|
+ .map_err(Error::other)?
|
|
|
.write(w)
|
|
.write(w)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -356,7 +356,7 @@ impl LenIo for &str {
|
|
|
fn write<L: Len>(&self, w: &mut Writer) -> Result<()> {
|
|
fn write<L: Len>(&self, w: &mut Writer) -> Result<()> {
|
|
|
let len = L::try_from(self.len() as u64)
|
|
let len = L::try_from(self.len() as u64)
|
|
|
.map_err(conversion)
|
|
.map_err(conversion)
|
|
|
- .map_err(other)?;
|
|
|
|
|
|
|
+ .map_err(Error::other)?;
|
|
|
len.write(w)?;
|
|
len.write(w)?;
|
|
|
w.write_all(self.as_bytes())
|
|
w.write_all(self.as_bytes())
|
|
|
}
|
|
}
|
|
@@ -405,16 +405,11 @@ impl<T: Io> Io for &T {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-// basically Error::other but not requiring nightly
|
|
|
|
|
-fn other(error: impl Into<Box<dyn std::error::Error + Send + Sync>>) -> Error {
|
|
|
|
|
- Error::new(ErrorKind::Other, error)
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
// discard error and use a string
|
|
// discard error and use a string
|
|
|
fn conversion<T>(_: T) -> Error {
|
|
fn conversion<T>(_: T) -> Error {
|
|
|
- other("failed to convert length to u64")
|
|
|
|
|
|
|
+ Error::other("failed to convert length to u64")
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
fn immutable_read() -> Error {
|
|
fn immutable_read() -> Error {
|
|
|
- other("immutable references cannot be read into")
|
|
|
|
|
|
|
+ Error::other("immutable references cannot be read into")
|
|
|
}
|
|
}
|