Skip to content

Commit

Permalink
refactor: remove unnecessary bounds from types
Browse files Browse the repository at this point in the history
This will allow future changes to enable zero copy deserialization to
avoid more complicated bounds on various types.

Signed-off-by: Ahmed Charles <[email protected]>
  • Loading branch information
ahmedcharles committed Feb 20, 2024
1 parent 9299517 commit e9193ab
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 11 deletions.
2 changes: 1 addition & 1 deletion ciborium-ll/src/dec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ impl<T> From<T> for Error<T> {
/// 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<R: Read> {
pub struct Decoder<R> {
reader: R,
offset: usize,
buffer: Option<Title>,
Expand Down
2 changes: 1 addition & 1 deletion ciborium-ll/src/enc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
8 changes: 5 additions & 3 deletions ciborium-ll/src/seg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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>,
Expand All @@ -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.
Expand Down
8 changes: 4 additions & 4 deletions ciborium/src/de/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions ciborium/src/ser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit e9193ab

Please sign in to comment.