From 7297bbb864778814ed59e99d0d6b05853704f06d Mon Sep 17 00:00:00 2001 From: zirkonya Date: Sun, 16 Aug 2026 15:01:43 +0200 Subject: change context representation --- src/codec/decode.rs | 43 +++++++++++++++++++++---------------------- 1 file changed, 21 insertions(+), 22 deletions(-) (limited to 'src/codec/decode.rs') diff --git a/src/codec/decode.rs b/src/codec/decode.rs index 3e03a84..31ed725 100644 --- a/src/codec/decode.rs +++ b/src/codec/decode.rs @@ -1,11 +1,11 @@ use std::{io::Read, sync::Arc}; -use crate::{DEFAULT_BUFFER_LEN, context::Context}; +use crate::{DEFAULT_BUFFER_LEN, codec::error::Result}; macro_rules! impl_decode { ($type: ty) => { - impl Decode for $type { - fn decode(reader: &mut dyn Read, _: &dyn Context) -> crate::codec::error::Result + impl Decode for $type { + fn decode(reader: &mut dyn Read, _: &mut Ctx) -> Result where Self: Sized, { @@ -18,14 +18,14 @@ macro_rules! impl_decode { }; } -pub trait Decode { - fn decode(reader: &mut dyn Read, ctx: &dyn Context) -> crate::codec::error::Result +pub trait Decode { + fn decode(reader: &mut dyn Read, ctx: &mut Ctx) -> Result where Self: Sized; } -impl Decode for bool { - fn decode(reader: &mut dyn Read, _: &dyn Context) -> crate::codec::error::Result +impl Decode for bool { + fn decode(reader: &mut dyn Read, _: &mut Ctx) -> Result where Self: Sized, { @@ -35,8 +35,8 @@ impl Decode for bool { } } -impl Decode for Option { - fn decode(reader: &mut dyn Read, ctx: &dyn Context) -> crate::codec::error::Result +impl> Decode for Option { + fn decode(reader: &mut dyn Read, ctx: &mut Ctx) -> Result where Self: Sized, { @@ -49,8 +49,8 @@ impl Decode for Option { } } -impl Decode for Vec { - fn decode(reader: &mut dyn Read, ctx: &dyn Context) -> crate::codec::error::Result +impl> Decode for Vec { + fn decode(reader: &mut dyn Read, ctx: &mut Ctx) -> Result where Self: Sized, { @@ -63,28 +63,27 @@ impl Decode for Vec { } } -impl Decode for String { - fn decode(reader: &mut dyn Read, _: &dyn Context) -> crate::codec::error::Result +impl Decode for String { + fn decode(reader: &mut dyn Read, _: &mut Ctx) -> Result where Self: Sized, { - // assume reader is limited let mut bytes: Vec = Vec::new(); reader.read_to_end(&mut bytes)?; Ok(String::from_utf8_lossy(&bytes).to_string()) } } -impl Decode for Arc<[u8]> { - fn decode(reader: &mut dyn Read, _: &dyn Context) -> crate::codec::error::Result { +impl Decode for Arc<[u8]> { + fn decode(reader: &mut dyn Read, _: &mut Ctx) -> Result { let mut buf = Vec::with_capacity(DEFAULT_BUFFER_LEN); reader.read_to_end(&mut buf)?; Ok(Arc::<[u8]>::from(buf.into_boxed_slice())) } } -impl Decode for [u8; S] { - fn decode(reader: &mut dyn Read, _: &dyn Context) -> crate::codec::error::Result +impl Decode for [u8; S] { + fn decode(reader: &mut dyn Read, _: &mut Ctx) -> Result where Self: Sized, { @@ -108,8 +107,8 @@ impl_decode!(i64); impl_decode!(i128); impl_decode!(isize); -impl Decode for f64 { - fn decode(reader: &mut dyn Read, ctx: &dyn Context) -> crate::codec::error::Result +impl Decode for f64 { + fn decode(reader: &mut dyn Read, ctx: &mut Ctx) -> Result where Self: Sized, { @@ -119,8 +118,8 @@ impl Decode for f64 { } } -impl Decode for f32 { - fn decode(reader: &mut dyn Read, ctx: &dyn Context) -> crate::codec::error::Result +impl Decode for f32 { + fn decode(reader: &mut dyn Read, ctx: &mut Ctx) -> Result where Self: Sized, { -- cgit v1.2.3