Skip to content

Commit 035182b

Browse files
introducing alloc feature
1 parent 94894f1 commit 035182b

File tree

6 files changed

+11
-5
lines changed

6 files changed

+11
-5
lines changed

Cargo.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,7 @@ serde = { version = "1", default-features = false, optional = true }
1919

2020
[features]
2121
default = ["std", "u128"]
22-
std = ["serde/std"]
22+
serde = ["alloc"]
23+
std = ["serde/std", "alloc"]
24+
alloc = []
2325
u128 = []

src/adjusted_byte.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
use core::cmp::Ordering;
22

3-
use alloc::fmt::{self, Display, Formatter};
3+
use core::fmt::{self, Display, Formatter};
4+
5+
#[cfg(any(feature = "serde", feature = "alloc"))]
46
use alloc::string::String;
57

68
use crate::{get_bytes, Byte, ByteUnit};
@@ -43,6 +45,7 @@ impl AdjustedByte {
4345
/// assert_eq!("1555 B", result);
4446
/// ```
4547
#[inline]
48+
#[cfg(feature = "alloc")]
4649
pub fn format(&self, fractional_digits: usize) -> String {
4750
if self.unit == ByteUnit::B {
4851
format!("{:.0} B", self.value)

src/byte.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use core::str::FromStr;
44
#[cfg(feature = "serde")]
55
use alloc::string::String;
66

7-
use alloc::fmt::{self, Display, Formatter};
7+
use core::fmt::{self, Display, Formatter};
88

99
use crate::{
1010
get_char_from_bytes, read_xib, AdjustedByte, ByteError, ByteUnit, ValueIncorrectError,

src/byte_error.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#[cfg(feature = "std")]
22
use std::error::Error;
33

4-
use alloc::fmt::{self, Display, Formatter};
4+
use core::fmt::{self, Display, Formatter};
55

66
#[derive(Debug, Clone)]
77
/// Error types for parsing values.

src/byte_unit.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use core::str::{from_utf8_unchecked, Bytes, FromStr};
44
#[cfg(feature = "serde")]
55
use alloc::string::String;
66

7-
use alloc::fmt::{self, Display, Formatter};
7+
use core::fmt::{self, Display, Formatter};
88

99
use crate::UnitIncorrectError;
1010

src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ features = ["serde"]
149149

150150
#![cfg_attr(not(feature = "std"), no_std)]
151151

152+
#[cfg(feature = "alloc")]
152153
#[macro_use]
153154
extern crate alloc;
154155

0 commit comments

Comments
 (0)