From 78b1d2a93ff1e49354070242e38e73f85e7ee93f Mon Sep 17 00:00:00 2001 From: Mathias Date: Tue, 18 May 2021 16:13:14 +0200 Subject: [PATCH 1/2] Update heapless to v0.7.0 and use const generics --- Cargo.toml | 2 +- src/decoder.rs | 3 --- src/publish.rs | 4 ---- src/subscribe.rs | 4 ++-- src/utils.rs | 2 +- 5 files changed, 4 insertions(+), 11 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index dc6b818..6ca28cf 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -24,7 +24,7 @@ std = ["bytes", "bytes/std", "serde/std"] [dependencies] bytes = { version = "1.0", default-features = false, optional = true } serde = { version = "1.0", features = ["derive"], optional = true } -heapless = "0.5.5" +heapless = "0.7" [dev-dependencies] proptest = "0.10.0" diff --git a/src/decoder.rs b/src/decoder.rs index 23cabba..4dcaeb4 100644 --- a/src/decoder.rs +++ b/src/decoder.rs @@ -1,8 +1,5 @@ use crate::*; -// use alloc::{string::String, vec::Vec}; -use heapless::{ArrayLength, String, Vec}; - /// Decode bytes from a [BytesMut] buffer as a [Packet] enum. /// /// The buf is never actually written to, it only takes a `BytesMut` instead of a `Bytes` to diff --git a/src/publish.rs b/src/publish.rs index e48ffba..8bc3613 100644 --- a/src/publish.rs +++ b/src/publish.rs @@ -1,9 +1,5 @@ use crate::{decoder::*, encoder::*, *}; -// use alloc::{string::String, vec::Vec}; -use heapless::{String, Vec, consts}; - - /// Publish packet ([MQTT 3.3]). /// /// [MQTT 3.3]: http://docs.oasis-open.org/mqtt/mqtt/v3.1.1/os/mqtt-v3.1.1-os.html#_Toc398718037 diff --git a/src/subscribe.rs b/src/subscribe.rs index 5b124d1..b449db1 100644 --- a/src/subscribe.rs +++ b/src/subscribe.rs @@ -5,12 +5,12 @@ use serde::{Deserialize, Serialize}; #[cfg(feature = "std")] pub(crate) type LimitedVec = std::vec::Vec; #[cfg(not(feature = "std"))] -pub(crate) type LimitedVec = heapless::Vec; +pub(crate) type LimitedVec = heapless::Vec; #[cfg(feature = "std")] pub(crate) type LimitedString = std::string::String; #[cfg(not(feature = "std"))] -pub(crate) type LimitedString = heapless::String; +pub(crate) type LimitedString = heapless::String<256>; /// Subscribe topic. /// diff --git a/src/utils.rs b/src/utils.rs index b852959..06d274b 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -31,7 +31,7 @@ pub enum Error { #[cfg(feature = "std")] InvalidProtocol(std::string::String, u8), #[cfg(not(feature = "std"))] - InvalidProtocol(heapless::String, u8), + InvalidProtocol(heapless::String<10>, u8), /// Tried to decode an invalid fixed header (packet type, flags, or remaining_length). InvalidHeader, /// Trying to encode/decode an invalid length. From d21cd00bcf9cdbf13b637fd8f8cbe12fe2247626 Mon Sep 17 00:00:00 2001 From: Mathias Date: Tue, 18 May 2021 16:14:27 +0200 Subject: [PATCH 2/2] Formatting --- src/decoder_test.rs | 5 ++++- src/utils.rs | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/decoder_test.rs b/src/decoder_test.rs index 2172bf3..4727e34 100644 --- a/src/decoder_test.rs +++ b/src/decoder_test.rs @@ -166,7 +166,10 @@ fn test_connect_wrong_version() { 0x00, 0x04, 'r' as u8, 'u' as u8, 's' as u8, 't' as u8, // username = 'rust' 0x00, 0x02, 'm' as u8, 'q' as u8, // password = 'mq' ]; - assert!(decode_slice(&mut data).is_err(), "Unknown version should return error"); + assert!( + decode_slice(&mut data).is_err(), + "Unknown version should return error" + ); } #[test] diff --git a/src/utils.rs b/src/utils.rs index 06d274b..c0d5f59 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -1,5 +1,5 @@ -use core::{convert::TryFrom, fmt, num::NonZeroU16}; use crate::encoder::write_u16; +use core::{convert::TryFrom, fmt, num::NonZeroU16}; #[cfg(feature = "derive")] use serde::{Deserialize, Serialize};