From e9193ab5739062b5995d33153d15b17a3218220e Mon Sep 17 00:00:00 2001 From: Ahmed Charles Date: Mon, 19 Feb 2024 20:08:04 -0800 Subject: [PATCH] refactor: remove unnecessary bounds from types This will allow future changes to enable zero copy deserialization to avoid more complicated bounds on various types. Signed-off-by: Ahmed Charles --- ciborium-ll/src/dec.rs | 2 +- ciborium-ll/src/enc.rs | 2 +- ciborium-ll/src/seg.rs | 8 +++++--- ciborium/src/de/mod.rs | 8 ++++---- ciborium/src/ser/mod.rs | 4 ++-- 5 files changed, 13 insertions(+), 11 deletions(-) diff --git a/ciborium-ll/src/dec.rs b/ciborium-ll/src/dec.rs index 3bd0889..f512901 100644 --- a/ciborium-ll/src/dec.rs +++ b/ciborium-ll/src/dec.rs @@ -28,7 +28,7 @@ impl From for Error { /// This decoder manages the low-level decoding of CBOR items into `Header` /// objects. It also contains utility functions for parsing segmented bytes /// and text inputs. -pub struct Decoder { +pub struct Decoder { reader: R, offset: usize, buffer: Option, diff --git a/ciborium-ll/src/enc.rs b/ciborium-ll/src/enc.rs index 44f2224..660f96e 100644 --- a/ciborium-ll/src/enc.rs +++ b/ciborium-ll/src/enc.rs @@ -6,7 +6,7 @@ use ciborium_io::Write; /// /// This structure wraps a writer and provides convenience functions for /// writing `Header` objects to the wire. -pub struct Encoder<W: Write>(W); +pub struct Encoder<W>(W); impl<W: Write> From<W> for Encoder<W> { #[inline] diff --git a/ciborium-ll/src/seg.rs b/ciborium-ll/src/seg.rs index 5377e07..9fc2fd6 100644 --- a/ciborium-ll/src/seg.rs +++ b/ciborium-ll/src/seg.rs @@ -111,7 +111,7 @@ impl Parser for Text { /// /// This type represents a single bytes or text segment on the wire. It can be /// read out in parsed chunks based on the size of the input scratch buffer. -pub struct Segment<'r, R: Read, P: Parser> { +pub struct Segment<'r, R, P> { reader: &'r mut Decoder<R>, unread: usize, offset: usize, @@ -169,14 +169,14 @@ enum State { /// /// CBOR allows for bytes or text items to be segmented. This type represents /// the state of that segmented input stream. -pub struct Segments<'r, R: Read, P: Parser> { +pub struct Segments<'r, R, P> { reader: &'r mut Decoder<R>, state: State, parser: PhantomData<P>, unwrap: fn(Header) -> Result<Option<usize>, ()>, } -impl<'r, R: Read, P: Parser> Segments<'r, R, P> { +impl<'r, R, P> Segments<'r, R, P> { #[inline] pub(crate) fn new( decoder: &'r mut Decoder<R>, @@ -189,7 +189,9 @@ impl<'r, R: Read, P: Parser> Segments<'r, R, P> { unwrap, } } +} +impl<'r, R: Read, P: Parser> Segments<'r, R, P> { /// Gets the next segment in the stream /// /// Returns `Ok(None)` at the conclusion of the stream. diff --git a/ciborium/src/de/mod.rs b/ciborium/src/de/mod.rs index 3d56fd5..f0a1e4e 100644 --- a/ciborium/src/de/mod.rs +++ b/ciborium/src/de/mod.rs @@ -49,7 +49,7 @@ impl<E: de::Error> Expected<E> for Header { } /// Deserializer -pub struct Deserializer<'b, R: Read> { +pub struct Deserializer<'b, R> { decoder: Decoder<R>, scratch: &'b mut [u8], recurse: usize, @@ -634,7 +634,7 @@ where } } -struct Access<'a, 'b, R: Read>(&'a mut Deserializer<'b, R>, Option<usize>); +struct Access<'a, 'b, R>(&'a mut Deserializer<'b, R>, Option<usize>); impl<'de, 'a, 'b, R: Read> de::SeqAccess<'de> for Access<'a, 'b, R> where @@ -757,7 +757,7 @@ where } } -struct BytesAccess<R: Read>(usize, Vec<u8>, core::marker::PhantomData<R>); +struct BytesAccess<R>(usize, Vec<u8>, core::marker::PhantomData<R>); impl<'de, R: Read> de::SeqAccess<'de> for BytesAccess<R> where @@ -787,7 +787,7 @@ where } } -struct TagAccess<'a, 'b, R: Read>(&'a mut Deserializer<'b, R>, usize); +struct TagAccess<'a, 'b, R>(&'a mut Deserializer<'b, R>, usize); impl<'de, 'a, 'b, R: Read> de::Deserializer<'de> for &mut TagAccess<'a, 'b, R> where diff --git a/ciborium/src/ser/mod.rs b/ciborium/src/ser/mod.rs index ff3d118..03dd1da 100644 --- a/ciborium/src/ser/mod.rs +++ b/ciborium/src/ser/mod.rs @@ -12,7 +12,7 @@ use ciborium_io::Write; use ciborium_ll::*; use serde::{ser, Serialize as _}; -struct Serializer<W: Write>(Encoder<W>); +struct Serializer<W>(Encoder<W>); impl<W: Write> From<W> for Serializer<W> { #[inline] @@ -335,7 +335,7 @@ macro_rules! end { }; } -struct CollectionSerializer<'a, W: Write> { +struct CollectionSerializer<'a, W> { encoder: &'a mut Serializer<W>, ending: bool, tag: bool,