|
@@ -8,6 +8,7 @@ use std::{
|
|
|
time::{Duration, SystemTime, UNIX_EPOCH}
|
|
time::{Duration, SystemTime, UNIX_EPOCH}
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
|
|
+use arrayvec::ArrayVec;
|
|
|
use paste::paste;
|
|
use paste::paste;
|
|
|
|
|
|
|
|
macro_rules! impl_basic {
|
|
macro_rules! impl_basic {
|
|
@@ -216,6 +217,26 @@ impl Io for SystemTime {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+impl<T: Io, const N: usize> Io for [T; N] {
|
|
|
|
|
+ fn read(r: &mut Reader) -> Result<Self> {
|
|
|
|
|
+ // this is used as a workaround for https://github.com/rust-lang/rust/issues/89379 not being stable
|
|
|
|
|
+ // :(((( literally 1 line and no unsafe
|
|
|
|
|
+ let array = [(); N]
|
|
|
|
|
+ .iter()
|
|
|
|
|
+ .map(|_| T::read(r))
|
|
|
|
|
+ .collect::<Result<ArrayVec<T, N>>>()?
|
|
|
|
|
+ .into_inner();
|
|
|
|
|
+ // SAFETY: this will never fail since [(); N] always has N items
|
|
|
|
|
+ Ok(unsafe { array.unwrap_unchecked() })
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ fn write(&self, w: &mut Writer) -> Result<()> {
|
|
|
|
|
+ self.iter()
|
|
|
|
|
+ .map(|item| item.write(w))
|
|
|
|
|
+ .collect()
|
|
|
|
|
+ }
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
// basically Error::other but not requiring nightly
|
|
// basically Error::other but not requiring nightly
|
|
|
fn other(error: impl Into<Box<dyn std::error::Error + Send + Sync>>) -> Error {
|
|
fn other(error: impl Into<Box<dyn std::error::Error + Send + Sync>>) -> Error {
|
|
|
Error::new(ErrorKind::Other, error)
|
|
Error::new(ErrorKind::Other, error)
|