Skip to content

Commit

Permalink
Bump heapless, no more generic-array
Browse files Browse the repository at this point in the history
  • Loading branch information
nickray committed Jun 10, 2021
1 parent 71b72fd commit 899b74f
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 18 deletions.
8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "cbor-smol"
version = "0.3.1"
version = "0.4.0"
authors = ["Nicolas Stalder <[email protected]>"]
edition = "2018"
description = "Streamlined serde serializer/deserializer for CBOR"
Expand All @@ -15,12 +15,12 @@ categories = ["development-tools", "embedded"]

[dependencies]
delog = "0.1.0-alpha.3"
heapless = "0.6"
heapless-bytes = "0.2"
heapless = "0.7"
heapless-bytes = "0.3"
serde = { version = "1", default-features = false }

[dev-dependencies]
heapless = { version = "0.6", features = ["serde"] }
heapless = { version = "0.7", features = ["serde"] }
serde = { version = "1", default-features = false, features = ["derive"] }

[features]
Expand Down
12 changes: 4 additions & 8 deletions src/de.rs
Original file line number Diff line number Diff line change
Expand Up @@ -907,30 +907,26 @@ mod tests {

#[test]
fn de_bytes() {
use heapless::consts::U64;

let mut buf = [0u8; 64];

let slice = b"thank you postcard!";
let bytes = crate::Bytes::<U64>::try_from_slice(slice).unwrap();
let bytes = crate::Bytes::<64>::from_slice(slice).unwrap();
let ser = cbor_serialize(&bytes, &mut buf).unwrap();
println!("serialized bytes = {:?}", ser);
let de: crate::Bytes::<U64> = from_bytes(&buf).unwrap();
let de: crate::Bytes::<64> = from_bytes(&buf).unwrap();
println!("deserialized bytes = {:?}", &de);
assert_eq!(&de, slice);
}

#[test]
fn de_str() {
use heapless::consts::U64;

let mut buf = [0u8; 64];

let string_slice = "thank you postcard, for blazing the path 🐝";
let mut string = heapless::String::<U64>::new();
let mut string = heapless::String::<64>::new();
string.push_str(string_slice).unwrap();
let _n = cbor_serialize(&string, &mut buf);
let de: heapless::String<U64> = from_bytes(&buf).unwrap();
let de: heapless::String<64> = from_bytes(&buf).unwrap();
assert_eq!(de, string_slice);
}

Expand Down
6 changes: 3 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
extern crate delog;
generate_macros!();

pub use heapless_bytes::{ArrayLength, Bytes, consts};
pub use heapless_bytes::Bytes;

pub mod de;
pub mod ser;
Expand Down Expand Up @@ -33,7 +33,7 @@ pub fn cbor_serialize<'a, 'b, T: serde::Serialize>(


/// Append serialization of object to existing bytes, returning length of serialized object.
pub fn cbor_serialize_extending_bytes<'a, 'b, N: ArrayLength<u8>, T: serde::Serialize>(
pub fn cbor_serialize_extending_bytes<'a, 'b, T: serde::Serialize, const N: usize>(
object: &'a T,
bytes: &'b mut Bytes<N>,
) -> Result<usize> {
Expand All @@ -47,7 +47,7 @@ pub fn cbor_serialize_extending_bytes<'a, 'b, N: ArrayLength<u8>, T: serde::Seri


/// Serialize object into newly allocated Bytes.
pub fn cbor_serialize_bytes<N: ArrayLength<u8>, T: serde::Serialize>(object: &T) -> Result<Bytes<N>> {
pub fn cbor_serialize_bytes<T: 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
4 changes: 1 addition & 3 deletions src/ser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,7 @@ impl<'a> Writer for SliceWriter<'a> {
}
}

impl<'a, N> Writer for &'a mut crate::Bytes<N>
where
N: crate::ArrayLength<u8>,
impl<'a, const N: usize> Writer for &'a mut crate::Bytes<N>
{
type Error = Error;

Expand Down

0 comments on commit 899b74f

Please sign in to comment.