diff --git a/Cargo.lock b/Cargo.lock index 1123416..9f158db 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2396,6 +2396,7 @@ name = "rnex-core" version = "0.1.1" dependencies = [ "anyhow", + "async-trait", "aws-config", "aws-sdk-s3", "base64", diff --git a/macros/src/lib.rs b/macros/src/lib.rs index d0172c2..5bd41bc 100644 --- a/macros/src/lib.rs +++ b/macros/src/lib.rs @@ -56,11 +56,11 @@ pub fn rmc_serialize(input: TokenStream) -> TokenStream { let tokens = quote! { impl rnex_core::rmc::structures::RmcSerialize for #ident{ #[inline(always)] - fn serialize(&self, writer: &mut impl ::std::io::Write) -> rnex_core::rmc::structures::Result<()>{ + fn serialize(&self, writer: &mut (impl ::std::io::Write + ?::std::marker::Sized)) -> rnex_core::rmc::structures::Result<()>{ #serialize } #[inline(always)] - fn deserialize(reader: &mut impl ::std::io::Read) -> rnex_core::rmc::structures::Result{ + fn deserialize(reader: &mut (impl ::std::io::Read + ?::std::marker::Sized)) -> rnex_core::rmc::structures::Result{ #deserialize } diff --git a/rnex-core/Cargo.toml b/rnex-core/Cargo.toml index c37f99a..16b8704 100644 --- a/rnex-core/Cargo.toml +++ b/rnex-core/Cargo.toml @@ -35,6 +35,7 @@ base64 = "0.22.1" sha2 = "0.10.9" urlencoding = "2.1.3" futures = "0.3.32" +async-trait = "0.1.89" [dev-dependencies] # criterion = "0.7.0" diff --git a/rnex-core/src/kerberos/mod.rs b/rnex-core/src/kerberos/mod.rs index e12aecd..1ca0576 100644 --- a/rnex-core/src/kerberos/mod.rs +++ b/rnex-core/src/kerberos/mod.rs @@ -128,11 +128,11 @@ impl Default for KerberosDateTime { } impl RmcSerialize for KerberosDateTime { - fn serialize(&self, writer: &mut impl Write) -> Result<()> { + fn serialize(&self, writer: &mut (impl Write + ?Sized)) -> Result<()> { Ok(self.0.serialize(writer)?) } - fn deserialize(reader: &mut impl Read) -> Result { + fn deserialize(reader: &mut (impl Read + ?Sized)) -> Result { Ok(Self(u64::deserialize(reader)?)) } } diff --git a/rnex-core/src/nex/user.rs b/rnex-core/src/nex/user.rs index 723cab3..970eb5b 100644 --- a/rnex-core/src/nex/user.rs +++ b/rnex-core/src/nex/user.rs @@ -928,5 +928,7 @@ impl Ranking for User { } impl MessageDelivery for User { - async fn deliver_message(&self, message: Any) {} + async fn deliver_message(&self, message: Any) -> Result<(), ErrorCode> { + Err(ErrorCode::Core_NotImplemented) + } } diff --git a/rnex-core/src/prudp/station_url.rs b/rnex-core/src/prudp/station_url.rs index e2d4abf..3fca35c 100644 --- a/rnex-core/src/prudp/station_url.rs +++ b/rnex-core/src/prudp/station_url.rs @@ -145,12 +145,15 @@ impl<'a> Into for &'a StationUrl { } impl RmcSerialize for StationUrl { - fn deserialize(reader: &mut impl Read) -> crate::rmc::structures::Result { + fn deserialize(reader: &mut (impl Read + ?Sized)) -> crate::rmc::structures::Result { let str = String::deserialize(reader)?; Self::try_from(str.as_str()).map_err(|_| StationUrlInvalid) } - fn serialize(&self, writer: &mut impl std::io::Write) -> crate::rmc::structures::Result<()> { + fn serialize( + &self, + writer: &mut (impl std::io::Write + ?Sized), + ) -> crate::rmc::structures::Result<()> { let str: String = self.into(); str.serialize(writer) diff --git a/rnex-core/src/rmc/protocols/message_delivery.rs b/rnex-core/src/rmc/protocols/message_delivery.rs index f1a11a7..ea4dd91 100644 --- a/rnex-core/src/rmc/protocols/message_delivery.rs +++ b/rnex-core/src/rmc/protocols/message_delivery.rs @@ -1,9 +1,12 @@ use macros::{method_id, rmc_proto}; -use crate::rmc::{response::ErrorCode, structures::any::Any}; +use crate::rmc::{ + response::ErrorCode, + structures::{Error, any::Any}, +}; -#[rmc_proto(27, NoReturn)] +#[rmc_proto(27)] pub trait MessageDelivery { #[method_id(1)] - async fn deliver_message(&self, message: Any); + async fn deliver_message(&self, message: Any) -> Result<(), ErrorCode>; } diff --git a/rnex-core/src/rmc/structures/any.rs b/rnex-core/src/rmc/structures/any.rs index 0f531d8..635c22b 100644 --- a/rnex-core/src/rmc/structures/any.rs +++ b/rnex-core/src/rmc/structures/any.rs @@ -9,7 +9,7 @@ pub struct Any { } impl RmcSerialize for Any { - fn serialize(&self, writer: &mut impl Write) -> Result<()> { + fn serialize(&self, writer: &mut (impl Write + ?Sized)) -> Result<()> { self.name.serialize(writer)?; let u32_len = self.data.len() as u32; @@ -18,7 +18,7 @@ impl RmcSerialize for Any { Ok(()) } - fn deserialize(reader: &mut impl Read) -> Result { + fn deserialize(mut reader: &mut (impl Read + ?Sized)) -> Result { let name = String::deserialize(reader)?; // also length ? diff --git a/rnex-core/src/rmc/structures/buffer.rs b/rnex-core/src/rmc/structures/buffer.rs index c147133..cb82160 100644 --- a/rnex-core/src/rmc/structures/buffer.rs +++ b/rnex-core/src/rmc/structures/buffer.rs @@ -3,7 +3,7 @@ use crate::rmc::structures::RmcSerialize; use std::io::{Read, Write}; impl<'a> RmcSerialize for &'a [u8] { - fn serialize(&self, writer: &mut impl Write) -> Result<()> { + fn serialize(&self, writer: &mut (impl Write + ?Sized)) -> Result<()> { let u32_size = self.len() as u32; writer.write(bytemuck::bytes_of(&u32_size))?; writer.write(self)?; @@ -12,7 +12,7 @@ impl<'a> RmcSerialize for &'a [u8] { } /// DO NOT USE (also maybe split off the serialize and deserialize functions at some point) - fn deserialize(_reader: &mut impl Read) -> Result { + fn deserialize(_reader: &mut (impl Read + ?Sized)) -> Result { panic!("cannot deserialize to a u8 slice reference (use this ONLY for writing)") } @@ -22,11 +22,11 @@ impl<'a> RmcSerialize for &'a [u8] { } impl RmcSerialize for Box<[u8]> { - fn serialize(&self, writer: &mut impl Write) -> Result<()> { + fn serialize(&self, writer: &mut (impl Write + ?Sized)) -> Result<()> { (&self[..]).serialize(writer) } - fn deserialize(reader: &mut impl Read) -> Result { + fn deserialize(reader: &mut (impl Read + ?Sized)) -> Result { Vec::deserialize(reader).map(|v| v.into_boxed_slice()) } diff --git a/rnex-core/src/rmc/structures/list.rs b/rnex-core/src/rmc/structures/list.rs index 7c7db8e..29b809c 100644 --- a/rnex-core/src/rmc/structures/list.rs +++ b/rnex-core/src/rmc/structures/list.rs @@ -7,7 +7,7 @@ use v_byte_helpers::{IS_BIG_ENDIAN, ReadExtensions}; // this is also for implementing `Buffer` this is tecnically not the same as its handled internaly // probably but as it has the same mapping it doesn't matter and simplifies things impl RmcSerialize for Vec { - fn serialize(&self, writer: &mut impl Write) -> crate::rmc::structures::Result<()> { + fn serialize(&self, writer: &mut (impl Write + ?Sized)) -> crate::rmc::structures::Result<()> { let u32_len = self.len() as u32; writer.write_all(bytes_of(&u32_len))?; @@ -18,7 +18,7 @@ impl RmcSerialize for Vec { Ok(()) } - fn deserialize(reader: &mut impl Read) -> crate::rmc::structures::Result { + fn deserialize(mut reader: &mut (impl Read + ?Sized)) -> crate::rmc::structures::Result { println!("reading list"); let len: u32 = reader.read_struct(IS_BIG_ENDIAN)?; @@ -42,7 +42,7 @@ impl RmcSerialize for Vec { } impl RmcSerialize for [T; LEN] { - fn serialize(&self, writer: &mut impl Write) -> crate::rmc::structures::Result<()> { + fn serialize(&self, writer: &mut (impl Write + ?Sized)) -> crate::rmc::structures::Result<()> { for i in 0..LEN { self[i].serialize(writer)?; } @@ -50,7 +50,7 @@ impl RmcSerialize for [T; LEN] { Ok(()) } - fn deserialize(reader: &mut impl Read) -> crate::rmc::structures::Result { + fn deserialize(reader: &mut (impl Read + ?Sized)) -> crate::rmc::structures::Result { let mut arr = [const { MaybeUninit::::uninit() }; LEN]; for i in 0..LEN { diff --git a/rnex-core/src/rmc/structures/mod.rs b/rnex-core/src/rmc/structures/mod.rs index 63ae484..1a17991 100644 --- a/rnex-core/src/rmc/structures/mod.rs +++ b/rnex-core/src/rmc/structures/mod.rs @@ -1,4 +1,5 @@ use crate::rmc::structures::helpers::DummyWriter; +use async_trait::async_trait; use std::io::{Read, Write}; use std::string::FromUtf8Error; use std::{fmt, io}; @@ -45,7 +46,7 @@ pub mod string_set; pub mod variant; pub trait RmcSerialize { - fn serialize(&self, writer: &mut impl Write) -> Result<()>; + fn serialize(&self, writer: &mut (impl Write + ?Sized)) -> Result<()>; fn serialize_write_size(&self) -> Result { let mut dummy = DummyWriter::new(); @@ -53,7 +54,7 @@ pub trait RmcSerialize { Ok(dummy.get_total_len()) } - fn deserialize(reader: &mut impl Read) -> Result + fn deserialize(reader: &mut (impl Read + ?Sized)) -> Result where Self: Sized; @@ -75,14 +76,61 @@ pub trait RmcSerialize { } } +trait SendWrite: Send + Write {} +impl SendWrite for T {} + +// beware that this trait throws away most of the optimizations which come with using +// the regular `Serialize` trait, ONLY use this when it is 100% required to have dyn +// compatibility +#[async_trait] +trait DynRmcSerialize: Send + Sync { + async fn serialize(&self, writer: &mut dyn SendWrite) -> Result<()>; +} + +#[async_trait] +impl DynRmcSerialize for T { + async fn serialize(&self, writer: &mut dyn SendWrite) -> Result<()> { + ::serialize(&self, writer) + } +} + impl RmcSerialize for () { - fn serialize(&self, _writer: &mut impl Write) -> Result<()> { + fn serialize(&self, _writer: &mut (impl Write + ?Sized)) -> Result<()> { Ok(()) } - fn deserialize(_reader: &mut impl Read) -> Result { + fn deserialize(_reader: &mut (impl Read + ?Sized)) -> Result { Ok(()) } fn serialize_write_size(&self) -> Result { Ok(0) } } + +trait RmcInternalAnyUnknownAs: AsRef + DynRmcSerialize + RmcStructInstance {} + +trait RmcCastable { + // consumes box and returns a Box containing a Box with the requested Struct details + fn cast_to(self: Box, destination: &RmcStructInfo) -> Box; +} + +struct RmcStructInfo { + inheritors: Vec<&'static RmcStructInfo>, + name: &'static str, + deserialize_abstract: fn(&mut dyn Read) -> Box, +} + +impl RmcStructInfo { + fn deserialze_abstract_as( + reader: &impl Read, + ) -> Box> { + todo!() + } +} + +trait RmcStruct { + fn get_struct_info() -> &'static RmcStructInfo; +} + +trait RmcStructInstance { + fn get_self_struct_info(&self) -> &'static RmcStructInfo; +} diff --git a/rnex-core/src/rmc/structures/networking.rs b/rnex-core/src/rmc/structures/networking.rs index bc95b9e..86e0acb 100644 --- a/rnex-core/src/rmc/structures/networking.rs +++ b/rnex-core/src/rmc/structures/networking.rs @@ -5,7 +5,7 @@ use std::net::{Ipv4Addr, Ipv6Addr, SocketAddr, SocketAddrV4, SocketAddrV6}; use v_byte_helpers::{IS_BIG_ENDIAN, ReadExtensions}; impl RmcSerialize for SocketAddr { - fn deserialize(reader: &mut impl std::io::Read) -> Result + fn deserialize(mut reader: &mut (impl Read + ?Sized)) -> Result where Self: Sized, { @@ -16,7 +16,7 @@ impl RmcSerialize for SocketAddr { v => Err(Error::UnexpectedValue(v as u64)), } } - fn serialize(&self, writer: &mut impl Write) -> Result<()> { + fn serialize(&self, writer: &mut (impl Write + ?Sized)) -> Result<()> { match self { SocketAddr::V4(v) => { writer.write_all(&[4])?; @@ -32,14 +32,14 @@ impl RmcSerialize for SocketAddr { } impl RmcSerialize for SocketAddrV4 { - fn serialize(&self, writer: &mut impl Write) -> crate::rmc::structures::Result<()> { + fn serialize(&self, writer: &mut (impl Write + ?Sized)) -> crate::rmc::structures::Result<()> { self.ip().to_bits().serialize(writer)?; self.port().serialize(writer)?; Ok(()) } - fn deserialize(reader: &mut impl Read) -> crate::rmc::structures::Result { + fn deserialize(reader: &mut (impl Read + ?Sized)) -> crate::rmc::structures::Result { let ip = u32::deserialize(reader)?; let port = u16::deserialize(reader)?; @@ -50,7 +50,7 @@ impl RmcSerialize for SocketAddrV4 { } } impl RmcSerialize for SocketAddrV6 { - fn serialize(&self, writer: &mut impl Write) -> crate::rmc::structures::Result<()> { + fn serialize(&self, writer: &mut (impl Write + ?Sized)) -> crate::rmc::structures::Result<()> { self.ip().to_bits().serialize(writer)?; self.port().serialize(writer)?; self.flowinfo().serialize(writer)?; @@ -59,7 +59,7 @@ impl RmcSerialize for SocketAddrV6 { Ok(()) } - fn deserialize(reader: &mut impl Read) -> crate::rmc::structures::Result { + fn deserialize(reader: &mut (impl Read + ?Sized)) -> crate::rmc::structures::Result { let ip = u128::deserialize(reader)?; let port = u16::deserialize(reader)?; let flowinfo = u32::deserialize(reader)?; @@ -78,13 +78,13 @@ impl RmcSerialize for SocketAddrV6 { } impl RmcSerialize for VirtualPort { - fn serialize(&self, writer: &mut impl Write) -> crate::rmc::structures::Result<()> { + fn serialize(&self, writer: &mut (impl Write + ?Sized)) -> crate::rmc::structures::Result<()> { self.0.serialize(writer)?; Ok(()) } - fn deserialize(reader: &mut impl Read) -> crate::rmc::structures::Result { + fn deserialize(reader: &mut (impl Read + ?Sized)) -> crate::rmc::structures::Result { Ok(Self(u8::deserialize(reader)?)) } fn serialize_write_size(&self) -> crate::rmc::structures::Result { diff --git a/rnex-core/src/rmc/structures/primitives.rs b/rnex-core/src/rmc/structures/primitives.rs index 6ce1c2f..a925165 100644 --- a/rnex-core/src/rmc/structures/primitives.rs +++ b/rnex-core/src/rmc/structures/primitives.rs @@ -5,12 +5,12 @@ use v_byte_helpers::{IS_BIG_ENDIAN, ReadExtensions}; impl RmcSerialize for u8 { #[inline(always)] - fn serialize(&self, writer: &mut impl Write) -> crate::rmc::structures::Result<()> { + fn serialize(&self, writer: &mut (impl Write + ?Sized)) -> crate::rmc::structures::Result<()> { Ok(writer.write_all(bytes_of(self))?) } #[inline(always)] - fn deserialize(reader: &mut impl Read) -> crate::rmc::structures::Result { + fn deserialize(mut reader: &mut (impl Read + ?Sized)) -> crate::rmc::structures::Result { Ok(reader.read_struct(IS_BIG_ENDIAN)?) } #[inline(always)] @@ -21,12 +21,12 @@ impl RmcSerialize for u8 { impl RmcSerialize for i8 { #[inline(always)] - fn serialize(&self, writer: &mut impl Write) -> crate::rmc::structures::Result<()> { + fn serialize(&self, writer: &mut (impl Write + ?Sized)) -> crate::rmc::structures::Result<()> { Ok(writer.write_all(bytes_of(self))?) } #[inline(always)] - fn deserialize(reader: &mut impl Read) -> crate::rmc::structures::Result { + fn deserialize(mut reader: &mut (impl Read + ?Sized)) -> crate::rmc::structures::Result { Ok(reader.read_struct(IS_BIG_ENDIAN)?) } #[inline(always)] @@ -37,11 +37,11 @@ impl RmcSerialize for i8 { impl RmcSerialize for u16 { #[inline(always)] - fn serialize(&self, writer: &mut impl Write) -> crate::rmc::structures::Result<()> { + fn serialize(&self, writer: &mut (impl Write + ?Sized)) -> crate::rmc::structures::Result<()> { Ok(writer.write_all(bytes_of(self))?) } #[inline(always)] - fn deserialize(reader: &mut impl Read) -> crate::rmc::structures::Result { + fn deserialize(mut reader: &mut (impl Read + ?Sized)) -> crate::rmc::structures::Result { Ok(reader.read_struct(IS_BIG_ENDIAN)?) } #[inline(always)] @@ -52,11 +52,11 @@ impl RmcSerialize for u16 { impl RmcSerialize for i16 { #[inline(always)] - fn serialize(&self, writer: &mut impl Write) -> crate::rmc::structures::Result<()> { + fn serialize(&self, writer: &mut (impl Write + ?Sized)) -> crate::rmc::structures::Result<()> { Ok(writer.write_all(bytes_of(self))?) } #[inline(always)] - fn deserialize(reader: &mut impl Read) -> crate::rmc::structures::Result { + fn deserialize(mut reader: &mut (impl Read + ?Sized)) -> crate::rmc::structures::Result { Ok(reader.read_struct(IS_BIG_ENDIAN)?) } #[inline(always)] @@ -67,11 +67,11 @@ impl RmcSerialize for i16 { impl RmcSerialize for u32 { #[inline(always)] - fn serialize(&self, writer: &mut impl Write) -> crate::rmc::structures::Result<()> { + fn serialize(&self, writer: &mut (impl Write + ?Sized)) -> crate::rmc::structures::Result<()> { Ok(writer.write_all(bytes_of(self))?) } #[inline(always)] - fn deserialize(reader: &mut impl Read) -> crate::rmc::structures::Result { + fn deserialize(mut reader: &mut (impl Read + ?Sized)) -> crate::rmc::structures::Result { Ok(reader.read_struct(IS_BIG_ENDIAN)?) } #[inline(always)] @@ -82,11 +82,11 @@ impl RmcSerialize for u32 { impl RmcSerialize for i32 { #[inline(always)] - fn serialize(&self, writer: &mut impl Write) -> crate::rmc::structures::Result<()> { + fn serialize(&self, writer: &mut (impl Write + ?Sized)) -> crate::rmc::structures::Result<()> { Ok(writer.write_all(bytes_of(self))?) } #[inline(always)] - fn deserialize(reader: &mut impl Read) -> crate::rmc::structures::Result { + fn deserialize(mut reader: &mut (impl Read + ?Sized)) -> crate::rmc::structures::Result { Ok(reader.read_struct(IS_BIG_ENDIAN)?) } #[inline(always)] @@ -97,11 +97,11 @@ impl RmcSerialize for i32 { impl RmcSerialize for u64 { #[inline(always)] - fn serialize(&self, writer: &mut impl Write) -> crate::rmc::structures::Result<()> { + fn serialize(&self, writer: &mut (impl Write + ?Sized)) -> crate::rmc::structures::Result<()> { Ok(writer.write_all(bytes_of(self))?) } #[inline(always)] - fn deserialize(reader: &mut impl Read) -> crate::rmc::structures::Result { + fn deserialize(mut reader: &mut (impl Read + ?Sized)) -> crate::rmc::structures::Result { Ok(reader.read_struct(IS_BIG_ENDIAN)?) } #[inline(always)] @@ -112,11 +112,11 @@ impl RmcSerialize for u64 { impl RmcSerialize for u128 { #[inline(always)] - fn serialize(&self, writer: &mut impl Write) -> crate::rmc::structures::Result<()> { + fn serialize(&self, writer: &mut (impl Write + ?Sized)) -> crate::rmc::structures::Result<()> { Ok(writer.write_all(bytes_of(self))?) } #[inline(always)] - fn deserialize(reader: &mut impl Read) -> crate::rmc::structures::Result { + fn deserialize(reader: &mut (impl Read + ?Sized)) -> crate::rmc::structures::Result { let mut data = 0u128; reader.read_exact(&mut bytes_of_mut(&mut data))?; Ok(data) @@ -129,11 +129,11 @@ impl RmcSerialize for u128 { impl RmcSerialize for i64 { #[inline(always)] - fn serialize(&self, writer: &mut impl Write) -> crate::rmc::structures::Result<()> { + fn serialize(&self, writer: &mut (impl Write + ?Sized)) -> crate::rmc::structures::Result<()> { Ok(writer.write_all(bytes_of(self))?) } #[inline(always)] - fn deserialize(reader: &mut impl Read) -> crate::rmc::structures::Result { + fn deserialize(mut reader: &mut (impl Read + ?Sized)) -> crate::rmc::structures::Result { Ok(reader.read_struct(IS_BIG_ENDIAN)?) } #[inline(always)] @@ -144,12 +144,12 @@ impl RmcSerialize for i64 { impl RmcSerialize for f64 { #[inline(always)] - fn serialize(&self, writer: &mut impl Write) -> crate::rmc::structures::Result<()> { + fn serialize(&self, writer: &mut (impl Write + ?Sized)) -> crate::rmc::structures::Result<()> { Ok(writer.write_all(bytes_of(self))?) } #[inline(always)] - fn deserialize(reader: &mut impl Read) -> crate::rmc::structures::Result { + fn deserialize(mut reader: &mut (impl Read + ?Sized)) -> crate::rmc::structures::Result { Ok(reader.read_struct(IS_BIG_ENDIAN)?) } #[inline(always)] @@ -160,7 +160,7 @@ impl RmcSerialize for f64 { impl RmcSerialize for bool { #[inline(always)] - fn serialize(&self, writer: &mut impl Write) -> crate::rmc::structures::Result<()> { + fn serialize(&self, writer: &mut (impl Write + ?Sized)) -> crate::rmc::structures::Result<()> { match self { true => writer.write_all(&[1])?, false => writer.write_all(&[0])?, @@ -169,7 +169,7 @@ impl RmcSerialize for bool { } #[inline(always)] - fn deserialize(reader: &mut impl Read) -> crate::rmc::structures::Result { + fn deserialize(reader: &mut (impl Read + ?Sized)) -> crate::rmc::structures::Result { Ok(u8::deserialize(reader)? != 0) } #[inline(always)] @@ -180,13 +180,13 @@ impl RmcSerialize for bool { impl RmcSerialize for (T, U) { #[inline(always)] - fn serialize(&self, writer: &mut impl Write) -> crate::rmc::structures::Result<()> { + fn serialize(&self, writer: &mut (impl Write + ?Sized)) -> crate::rmc::structures::Result<()> { self.0.serialize(writer)?; self.1.serialize(writer)?; Ok(()) } #[inline(always)] - fn deserialize(reader: &mut impl Read) -> crate::rmc::structures::Result { + fn deserialize(reader: &mut (impl Read + ?Sized)) -> crate::rmc::structures::Result { let first = T::deserialize(reader)?; let second = U::deserialize(reader)?; @@ -200,14 +200,14 @@ impl RmcSerialize for (T, U) { impl RmcSerialize for (T, U, V) { #[inline(always)] - fn serialize(&self, writer: &mut impl Write) -> crate::rmc::structures::Result<()> { + fn serialize(&self, writer: &mut (impl Write + ?Sized)) -> crate::rmc::structures::Result<()> { self.0.serialize(writer)?; self.1.serialize(writer)?; self.2.serialize(writer)?; Ok(()) } #[inline(always)] - fn deserialize(reader: &mut impl Read) -> crate::rmc::structures::Result { + fn deserialize(reader: &mut (impl Read + ?Sized)) -> crate::rmc::structures::Result { let first = T::deserialize(reader)?; let second = U::deserialize(reader)?; let third = V::deserialize(reader)?; @@ -226,7 +226,7 @@ impl RmcSeri for (T, U, V, W) { #[inline(always)] - fn serialize(&self, writer: &mut impl Write) -> crate::rmc::structures::Result<()> { + fn serialize(&self, writer: &mut (impl Write + ?Sized)) -> crate::rmc::structures::Result<()> { self.0.serialize(writer)?; self.1.serialize(writer)?; self.2.serialize(writer)?; @@ -234,7 +234,7 @@ impl RmcSeri Ok(()) } #[inline(always)] - fn deserialize(reader: &mut impl Read) -> crate::rmc::structures::Result { + fn deserialize(reader: &mut (impl Read + ?Sized)) -> crate::rmc::structures::Result { let first = T::deserialize(reader)?; let second = U::deserialize(reader)?; let third = V::deserialize(reader)?; @@ -255,7 +255,7 @@ impl crate::rmc::structures::Result<()> { + fn serialize(&self, writer: &mut (impl Write + ?Sized)) -> crate::rmc::structures::Result<()> { self.0.serialize(writer)?; self.1.serialize(writer)?; self.2.serialize(writer)?; @@ -266,7 +266,7 @@ impl crate::rmc::structures::Result { + fn deserialize(reader: &mut (impl Read + ?Sized)) -> crate::rmc::structures::Result { let first = T::deserialize(reader)?; let second = U::deserialize(reader)?; let third = V::deserialize(reader)?; @@ -295,7 +295,7 @@ impl< > RmcSerialize for (T, U, V, W, X, Y) { #[inline(always)] - fn serialize(&self, writer: &mut impl Write) -> crate::rmc::structures::Result<()> { + fn serialize(&self, writer: &mut (impl Write + ?Sized)) -> crate::rmc::structures::Result<()> { self.0.serialize(writer)?; self.1.serialize(writer)?; self.2.serialize(writer)?; @@ -307,7 +307,7 @@ impl< } #[inline(always)] - fn deserialize(reader: &mut impl Read) -> crate::rmc::structures::Result { + fn deserialize(reader: &mut (impl Read + ?Sized)) -> crate::rmc::structures::Result { let first = T::deserialize(reader)?; let second = U::deserialize(reader)?; let third = V::deserialize(reader)?; @@ -339,7 +339,7 @@ impl< > RmcSerialize for (T, U, V, W, X, Y, Z) { #[inline(always)] - fn serialize(&self, writer: &mut impl Write) -> crate::rmc::structures::Result<()> { + fn serialize(&self, writer: &mut (impl Write + ?Sized)) -> crate::rmc::structures::Result<()> { self.0.serialize(writer)?; self.1.serialize(writer)?; self.2.serialize(writer)?; @@ -351,7 +351,7 @@ impl< Ok(()) } #[inline(always)] - fn deserialize(reader: &mut impl Read) -> crate::rmc::structures::Result { + fn deserialize(reader: &mut (impl Read + ?Sized)) -> crate::rmc::structures::Result { let first = T::deserialize(reader)?; let second = U::deserialize(reader)?; let third = V::deserialize(reader)?; @@ -386,7 +386,7 @@ impl< > RmcSerialize for (T, U, V, W, X, Y, Z, A) { #[inline(always)] - fn serialize(&self, writer: &mut impl Write) -> crate::rmc::structures::Result<()> { + fn serialize(&self, writer: &mut (impl Write + ?Sized)) -> crate::rmc::structures::Result<()> { self.0.serialize(writer)?; self.1.serialize(writer)?; self.2.serialize(writer)?; @@ -399,7 +399,7 @@ impl< Ok(()) } #[inline(always)] - fn deserialize(reader: &mut impl Read) -> crate::rmc::structures::Result { + fn deserialize(reader: &mut (impl Read + ?Sized)) -> crate::rmc::structures::Result { let first = T::deserialize(reader)?; let second = U::deserialize(reader)?; let third = V::deserialize(reader)?; @@ -437,7 +437,7 @@ impl< > RmcSerialize for (T, U, V, W, X, Y, Z, A, B) { #[inline(always)] - fn serialize(&self, writer: &mut impl Write) -> crate::rmc::structures::Result<()> { + fn serialize(&self, writer: &mut (impl Write + ?Sized)) -> crate::rmc::structures::Result<()> { self.0.serialize(writer)?; self.1.serialize(writer)?; self.2.serialize(writer)?; @@ -451,7 +451,7 @@ impl< Ok(()) } #[inline(always)] - fn deserialize(reader: &mut impl Read) -> crate::rmc::structures::Result { + fn deserialize(reader: &mut (impl Read + ?Sized)) -> crate::rmc::structures::Result { let first = T::deserialize(reader)?; let second = U::deserialize(reader)?; let third = V::deserialize(reader)?; @@ -482,11 +482,11 @@ impl< impl RmcSerialize for Box { #[inline(always)] - fn serialize(&self, writer: &mut impl Write) -> crate::rmc::structures::Result<()> { + fn serialize(&self, writer: &mut (impl Write + ?Sized)) -> crate::rmc::structures::Result<()> { self.as_ref().serialize(writer) } #[inline(always)] - fn deserialize(reader: &mut impl Read) -> crate::rmc::structures::Result { + fn deserialize(reader: &mut (impl Read + ?Sized)) -> crate::rmc::structures::Result { T::deserialize(reader).map(Box::new) } #[inline(always)] diff --git a/rnex-core/src/rmc/structures/qbuffer.rs b/rnex-core/src/rmc/structures/qbuffer.rs index 7f2aa7b..171f749 100644 --- a/rnex-core/src/rmc/structures/qbuffer.rs +++ b/rnex-core/src/rmc/structures/qbuffer.rs @@ -1,13 +1,13 @@ -use std::io::{Read, Write}; -use bytemuck::bytes_of; -use v_byte_helpers::{IS_BIG_ENDIAN, ReadExtensions}; use crate::rmc::structures::{Result, RmcSerialize}; +use bytemuck::bytes_of; +use std::io::{Read, Write}; +use v_byte_helpers::{IS_BIG_ENDIAN, ReadExtensions}; #[derive(Clone, Debug, Default)] pub struct QBuffer(pub Vec); -impl RmcSerialize for QBuffer{ - fn serialize(&self, writer: &mut impl Write) -> Result<()> { +impl RmcSerialize for QBuffer { + fn serialize(&self, writer: &mut (impl Write + ?Sized)) -> Result<()> { let len_u16 = self.0.len() as u16; writer.write(bytes_of(&len_u16))?; @@ -16,7 +16,7 @@ impl RmcSerialize for QBuffer{ Ok(()) } - fn deserialize(reader: &mut impl Read) -> Result { + fn deserialize(mut reader: &mut (impl Read + ?Sized)) -> Result { let size: u16 = reader.read_struct(IS_BIG_ENDIAN)?; let mut vec = vec![0; size as usize]; @@ -25,4 +25,4 @@ impl RmcSerialize for QBuffer{ Ok(Self(vec)) } -} \ No newline at end of file +} diff --git a/rnex-core/src/rmc/structures/qresult.rs b/rnex-core/src/rmc/structures/qresult.rs index 13b79d7..7048495 100644 --- a/rnex-core/src/rmc/structures/qresult.rs +++ b/rnex-core/src/rmc/structures/qresult.rs @@ -26,12 +26,12 @@ impl QResult { } impl RmcSerialize for QResult { - fn serialize(&self, writer: &mut impl Write) -> Result<()> { + fn serialize(&self, writer: &mut (impl Write + ?Sized)) -> Result<()> { writer.write(bytes_of(self))?; Ok(()) } - fn deserialize(reader: &mut impl Read) -> Result { + fn deserialize(mut reader: &mut (impl Read + ?Sized)) -> Result { let result: Self = reader.read_struct(IS_BIG_ENDIAN)?; println!("reading qresult: {:x}", result.0); Ok(result) diff --git a/rnex-core/src/rmc/structures/rmc_struct.rs b/rnex-core/src/rmc/structures/rmc_struct.rs index 7660f96..92cdff1 100644 --- a/rnex-core/src/rmc/structures/rmc_struct.rs +++ b/rnex-core/src/rmc/structures/rmc_struct.rs @@ -36,7 +36,7 @@ impl Write for OnlyWriteVec<'_> { } #[cfg(feature = "rmc_struct_header")] -pub fn write_struct( +pub fn write_struct( writer: &mut T, version: u8, inner_size: u32, @@ -54,7 +54,7 @@ pub fn write_struct( } #[cfg(not(feature = "rmc_struct_header"))] -pub fn write_struct( +pub fn write_struct( writer: &mut T, _version: u8, _inner_size: u32, @@ -63,12 +63,12 @@ pub fn write_struct( pred(writer) } -pub struct SubRead<'a, T: Read> { +pub struct SubRead<'a, T: Read + ?Sized> { left_to_read: usize, origin: &'a mut T, } -impl<'a, T: Read> SubRead<'a, T> { +impl<'a, T: Read + ?Sized> SubRead<'a, T> { pub const fn new(origin: &'a mut T, left_to_read: usize) -> Self { Self { left_to_read, @@ -77,7 +77,7 @@ impl<'a, T: Read> SubRead<'a, T> { } } -impl Read for SubRead<'_, T> { +impl Read for SubRead<'_, T> { #[inline(always)] fn read(&mut self, buf: &mut [u8]) -> io::Result { let max_read = max(self.left_to_read, buf.len()); @@ -100,8 +100,8 @@ impl Read for SubRead<'_, T> { } #[cfg(feature = "rmc_struct_header")] -pub fn read_struct( - reader: &mut R, +pub fn read_struct( + mut reader: &mut R, version: u8, pred: impl FnOnce(&mut SubRead) -> Result, ) -> Result { @@ -120,7 +120,7 @@ pub fn read_struct( } #[cfg(not(feature = "rmc_struct_header"))] -pub fn read_struct( +pub fn read_struct( mut reader: &mut R, _version: u8, pred: impl FnOnce(&mut R) -> Result, diff --git a/rnex-core/src/rmc/structures/string.rs b/rnex-core/src/rmc/structures/string.rs index 8830822..59474cc 100644 --- a/rnex-core/src/rmc/structures/string.rs +++ b/rnex-core/src/rmc/structures/string.rs @@ -5,7 +5,7 @@ use std::io::{Read, Write}; use v_byte_helpers::{IS_BIG_ENDIAN, ReadExtensions}; impl RmcSerialize for String { - fn deserialize(reader: &mut impl Read) -> Result { + fn deserialize(mut reader: &mut (impl Read + ?Sized)) -> Result { let len: u16 = reader.read_struct(IS_BIG_ENDIAN)?; if len == 0 { return Ok("".to_string()); @@ -19,7 +19,7 @@ impl RmcSerialize for String { Ok(String::from_utf8(data)?) } - fn serialize(&self, writer: &mut impl Write) -> Result<()> { + fn serialize(&self, writer: &mut (impl Write + ?Sized)) -> Result<()> { (&self[..]).serialize(writer) } fn serialize_write_size(&self) -> Result { @@ -28,10 +28,10 @@ impl RmcSerialize for String { } impl RmcSerialize for &str { - fn deserialize(_reader: &mut impl Read) -> Result { + fn deserialize(_reader: &mut (impl Read + ?Sized)) -> Result { panic!("cannot serialize to &str") } - fn serialize(&self, writer: &mut impl Write) -> Result<()> { + fn serialize(&self, writer: &mut (impl Write + ?Sized)) -> Result<()> { let u16_len: u16 = (self.len() + 1) as u16; writer.write_all(bytes_of(&u16_len))?; diff --git a/rnex-core/src/rmc/structures/string_set.rs b/rnex-core/src/rmc/structures/string_set.rs index efb6c05..40ca258 100644 --- a/rnex-core/src/rmc/structures/string_set.rs +++ b/rnex-core/src/rmc/structures/string_set.rs @@ -1,4 +1,10 @@ -use std::{collections::HashSet, hash::Hash, str::FromStr, string::ToString}; +use std::{ + collections::HashSet, + hash::Hash, + io::{Read, Write}, + str::FromStr, + string::ToString, +}; use rnex_core::rmc::structures::RmcSerialize; @@ -55,13 +61,13 @@ impl RmcSerialize for StringSet where ::Err: std::error::Error + Send + Sync + 'static, { - fn deserialize(reader: &mut impl std::io::prelude::Read) -> super::Result + fn deserialize(reader: &mut (impl Read + ?Sized)) -> super::Result where Self: Sized, { Self::from_str(&String::deserialize(reader)?).map_err(super::Error::Other) } - fn serialize(&self, writer: &mut impl std::io::prelude::Write) -> super::Result<()> { + fn serialize(&self, writer: &mut (impl Write + ?Sized)) -> super::Result<()> { self.to_string().serialize(writer) } fn serialize_write_size(&self) -> super::Result { diff --git a/rnex-core/src/rmc/structures/variant.rs b/rnex-core/src/rmc/structures/variant.rs index c5c41b0..45b29da 100644 --- a/rnex-core/src/rmc/structures/variant.rs +++ b/rnex-core/src/rmc/structures/variant.rs @@ -16,7 +16,7 @@ pub enum Variant { } impl RmcSerialize for Variant { - fn serialize(&self, writer: &mut impl Write) -> Result<()> { + fn serialize(&self, writer: &mut (impl Write + ?Sized)) -> Result<()> { match self { Variant::None => { writer.write_all(&[0])?; @@ -50,7 +50,7 @@ impl RmcSerialize for Variant { Ok(()) } - fn deserialize(reader: &mut impl Read) -> Result { + fn deserialize(reader: &mut (impl Read + ?Sized)) -> Result { match u8::deserialize(reader)? { 0 => Ok(Variant::None), 1 => Ok(Variant::SInt64(i64::deserialize(reader)?)), diff --git a/rnex-core/src/rnex_proxy_common.rs b/rnex-core/src/rnex_proxy_common.rs index 54de962..adaac28 100644 --- a/rnex-core/src/rnex_proxy_common.rs +++ b/rnex-core/src/rnex_proxy_common.rs @@ -1,7 +1,7 @@ use crate::{PID, prudp::socket_addr::PRUDPSockAddr}; use macros::RmcSerialize; -#[derive(Debug, RmcSerialize, PartialEq, Eq)] +#[derive(Debug, PartialEq, Eq, RmcSerialize)] #[rmc_struct(0)] pub struct ConnectionInitData { pub prudpsock_addr: PRUDPSockAddr,