Skip to content

Commit

Permalink
Merge branch 'main' of github.com:enarx/ciborium into rfc8949
Browse files Browse the repository at this point in the history
  • Loading branch information
hoxxep committed Dec 5, 2024
2 parents fe4e2e2 + 19c20be commit 15b250e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
4 changes: 4 additions & 0 deletions ciborium/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,10 @@ pub use crate::ser::{into_writer_canonical, to_vec, to_vec_canonical};
#[deprecated(since = "0.3.0", note = "Please use `to_vec` instead")]
pub use crate::ser::to_vec as into_vec;

#[cfg(feature = "std")]
#[doc(inline)]
pub use crate::ser::into_vec;

#[doc(inline)]
pub use crate::value::Value;

Expand Down
12 changes: 12 additions & 0 deletions ciborium/src/ser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -868,3 +868,15 @@ where
let mut encoder: Serializer<W, C> = Serializer::new(writer);
value.serialize(&mut encoder)
}

#[cfg(feature = "std")]
/// Serializes as CBOR into a new Vec<u8>
#[inline]
pub fn into_vec<T: ?Sized + ser::Serialize>(
value: &T,
) -> Result<Vec<u8>, Error<<Vec<u8> as ciborium_io::Write>::Error>> {
let mut vector = vec![];
let mut encoder = Serializer::from(&mut vector);
value.serialize(&mut encoder)?;
Ok(vector)
}

0 comments on commit 15b250e

Please sign in to comment.