Skip to content

Commit

Permalink
Add ?Sized trait bound
Browse files Browse the repository at this point in the history
Fix #9
  • Loading branch information
sosthene-nitrokey committed Oct 2, 2024
1 parent f177481 commit 5d9247c
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ pub use error::{Error, Result};
// pub use de::take_from_bytes;

// kudos to postcard, this is much nicer than returning size
pub fn cbor_serialize<'a, T: serde::Serialize>(
pub fn cbor_serialize<'a, T: ?Sized + serde::Serialize>(
object: &T,
buffer: &'a mut [u8],
) -> Result<&'a [u8]> {
Expand All @@ -33,7 +33,7 @@ pub fn cbor_serialize<'a, T: serde::Serialize>(
}

/// Append serialization of object to existing bytes, returning length of serialized object.
pub fn cbor_serialize_extending_bytes<T: serde::Serialize, const N: usize>(
pub fn cbor_serialize_extending_bytes<T: ?Sized + serde::Serialize, const N: usize>(
object: &T,
bytes: &mut Bytes<N>,
) -> Result<usize> {
Expand All @@ -46,7 +46,9 @@ pub fn cbor_serialize_extending_bytes<T: serde::Serialize, const N: usize>(
}

/// Serialize object into newly allocated Bytes.
pub fn cbor_serialize_bytes<T: serde::Serialize, const N: usize>(object: &T) -> Result<Bytes<N>> {
pub fn cbor_serialize_bytes<T: ?Sized + serde::Serialize, const N: usize>(
object: &T,
) -> Result<Bytes<N>> {
let mut data = Bytes::<N>::new();
cbor_serialize_extending_bytes(object, &mut data)?;
Ok(data)
Expand Down

0 comments on commit 5d9247c

Please sign in to comment.