Skip to content

Commit 8961910

Browse files
MabezDeveldruin
authored andcommitted
make heapless optional
* Makes heapless an optional dep * Feature gate heapless uses throughout the code * Enable heapless feature by default for backwards compat
1 parent 5f2884b commit 8961910

File tree

4 files changed

+16
-4
lines changed

4 files changed

+16
-4
lines changed

CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
77

88
## [Unreleased]
99

10-
...
10+
### Added
11+
12+
- Support for opting out of heapless integration
1113

1214
## [v0.3.0] - 2021-04-29
1315
### Added

Cargo.toml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,12 @@ repository = "https://github.com/rust-embedded-community/serde-json-core"
1212
version = "0.3.0"
1313

1414
[dependencies]
15-
heapless = "0.6.1"
1615
ryu = "1.0.5"
1716

17+
[dependencies.heapless]
18+
version = "0.6.1"
19+
optional = true
20+
1821
[dependencies.serde]
1922
default-features = false
2023
version = "1.0.80"
@@ -23,5 +26,6 @@ version = "1.0.80"
2326
serde_derive = "1.0.80"
2427

2528
[features]
26-
custom-error-messages = []
29+
default = ["heapless"]
30+
custom-error-messages = ["heapless"]
2731
std = ["serde/std"]

src/lib.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,11 @@ pub mod ser;
6565
#[doc(inline)]
6666
pub use self::de::{from_slice, from_str};
6767
#[doc(inline)]
68-
pub use self::ser::{to_slice, to_string, to_vec};
68+
pub use self::ser::to_slice;
69+
#[cfg(feature = "heapless")]
70+
pub use self::ser::{to_string, to_vec};
6971

72+
#[cfg(feature = "heapless")]
7073
pub use heapless;
7174

7275
#[allow(deprecated)]

src/ser/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use core::fmt;
55
use serde::ser;
66
use serde::ser::SerializeStruct as _;
77

8+
#[cfg(feature = "heapless")]
89
use heapless::{String, Vec};
910

1011
use self::map::SerializeMap;
@@ -423,6 +424,7 @@ impl<'a, 'b: 'a> ser::Serializer for &'a mut Serializer<'b> {
423424
}
424425

425426
/// Serializes the given data structure as a string of JSON text
427+
#[cfg(feature = "heapless")]
426428
pub fn to_string<B, T>(value: &T) -> Result<String<B>>
427429
where
428430
B: heapless::ArrayLength<u8>,
@@ -432,6 +434,7 @@ where
432434
}
433435

434436
/// Serializes the given data structure as a JSON byte vector
437+
#[cfg(feature = "heapless")]
435438
pub fn to_vec<B, T>(value: &T) -> Result<Vec<u8, B>>
436439
where
437440
B: heapless::ArrayLength<u8>,

0 commit comments

Comments
 (0)