Skip to content

Commit

Permalink
refactor: deprecate into_vec in favour of to_vec
Browse files Browse the repository at this point in the history
Signed-off-by: Liam Gray <[email protected]>
  • Loading branch information
hoxxep committed Dec 5, 2024
1 parent 2a3025a commit fe4e2e2
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 5 deletions.
1 change: 0 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ jobs:
- {name: ciborium-ll}
- {name: ciborium}
- {name: ciborium, feat: std}
- {name: ciborium, feat: canonical}
- {name: ciborium-io}
- {name: ciborium-io, feat: alloc}
- {name: ciborium-io, feat: std}
Expand Down
5 changes: 4 additions & 1 deletion ciborium-ll/src/enc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,26 @@ impl<W: Write> From<W> for Encoder<W> {
impl<W: Write> Write for Encoder<W> {
type Error = W::Error;

#[inline]
fn write_all(&mut self, data: &[u8]) -> Result<(), Self::Error> {
self.0.write_all(data)
}

#[inline]
fn flush(&mut self) -> Result<(), Self::Error> {
self.0.flush()
}
}

impl<W: Write> Encoder<W> {
/// Unwraps the `Write`, consuming the `Encoder`.
#[inline]
pub fn into_inner(self) -> W {
self.0
}

/// Push a `Header` to the wire
#[inline]
#[inline(always)]
pub fn push(&mut self, header: Header) -> Result<(), W::Error> {
let title = Title::from(header);

Expand Down
2 changes: 2 additions & 0 deletions ciborium-ll/src/hdr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ pub enum Header {
impl TryFrom<Title> for Header {
type Error = InvalidError;

#[inline]
fn try_from(title: Title) -> Result<Self, Self::Error> {
let opt = |minor| {
Some(match minor {
Expand Down Expand Up @@ -116,6 +117,7 @@ impl TryFrom<Title> for Header {
}

impl From<Header> for Title {
#[inline(always)]
fn from(header: Header) -> Self {
let int = |i: u64| match i {
x if x <= 23 => Minor::This(i as u8),
Expand Down
2 changes: 1 addition & 1 deletion ciborium/src/ser/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use serde::ser::{Error as SerError, StdError};
pub enum Error<T> {
/// An error occurred while writing bytes
///
/// Contains the underlying error reaturned while writing.
/// Contains the underlying error returned while writing.
Io(T),

/// An error indicating a value that cannot be serialized
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 @@ -508,7 +508,7 @@ where
serializer,
collection_type,
length,
tag_written: false,
tag_written: !matches!(collection_type, CollectionType::Tag),
#[cfg(feature = "std")]
cache_keys: Vec::new(),
#[cfg(feature = "std")]
Expand Down Expand Up @@ -645,7 +645,7 @@ where
&mut self,
value: &U,
) -> Result<(), Self::Error> {
if self.tag_written || !matches!(self.collection_type, CollectionType::Tag) {
if self.tag_written {
// untagged tuples are CollectionType::Array to skip writing the tag header
return self.inline_serialize_value(value);
}
Expand Down

0 comments on commit fe4e2e2

Please sign in to comment.