Skip to content

Commit

Permalink
Merge pull request #41 from MathiasKoch/chore/bump-heapless
Browse files Browse the repository at this point in the history
Update heapless to v0.7.0 and use const generics
  • Loading branch information
00imvj00 authored May 20, 2021
2 parents 395feb6 + d21cd00 commit 628fbb6
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 13 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
3 changes: 0 additions & 3 deletions src/decoder.rs
Original file line number Diff line number Diff line change
@@ -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
Expand Down
5 changes: 4 additions & 1 deletion src/decoder_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
4 changes: 0 additions & 4 deletions src/publish.rs
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/subscribe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ use serde::{Deserialize, Serialize};
#[cfg(feature = "std")]
pub(crate) type LimitedVec<T> = std::vec::Vec<T>;
#[cfg(not(feature = "std"))]
pub(crate) type LimitedVec<T> = heapless::Vec<T, heapless::consts::U5>;
pub(crate) type LimitedVec<T> = heapless::Vec<T, 5>;

#[cfg(feature = "std")]
pub(crate) type LimitedString = std::string::String;
#[cfg(not(feature = "std"))]
pub(crate) type LimitedString = heapless::String<heapless::consts::U256>;
pub(crate) type LimitedString = heapless::String<256>;

/// Subscribe topic.
///
Expand Down
4 changes: 2 additions & 2 deletions src/utils.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand Down Expand Up @@ -31,7 +31,7 @@ pub enum Error {
#[cfg(feature = "std")]
InvalidProtocol(std::string::String, u8),
#[cfg(not(feature = "std"))]
InvalidProtocol(heapless::String<heapless::consts::U10>, 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.
Expand Down

0 comments on commit 628fbb6

Please sign in to comment.