Skip to content

Commit 59c1de5

Browse files
committed
feat: optional "ser" to make no_std work
Signed-off-by: Woshiluo Luo <[email protected]>
1 parent ba8f0e5 commit 59c1de5

File tree

4 files changed

+7
-5
lines changed

4 files changed

+7
-5
lines changed

Cargo.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,12 @@ edition = "2024"
1515

1616
[dependencies]
1717
serde = { version = "1.0", default-features = false }
18-
erased-serde = "0.4"
1918
serde_derive = "1.0"
19+
erased-serde = { version = "0.4", optional = true }
2020

2121
[features]
22-
default = ["std"]
22+
default = ["std", "ser"]
2323

24+
ser = ["dep:erased-serde"]
2425
std = ["serde/std"]
2526
alloc = ["serde/alloc"]

src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ extern crate alloc;
2020

2121
pub mod de;
2222
pub mod error;
23+
#[cfg(feature = "ser")]
2324
pub mod ser;
2425
pub mod utils;
2526
pub mod value;

src/ser/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ pub enum Error {
7373
}
7474

7575
impl core::fmt::Display for Error {
76-
fn fmt(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
76+
fn fmt(&self, formatter: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
7777
write!(formatter, "{:?}", self)
7878
}
7979
}
@@ -83,7 +83,7 @@ impl core::error::Error for Error {}
8383
impl serde::ser::Error for Error {
8484
fn custom<T>(_msg: T) -> Self
8585
where
86-
T: std::fmt::Display,
86+
T: core::fmt::Display,
8787
{
8888
Self::Unknown
8989
}

src/ser/serializer.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
use super::Error;
21
use super::patch::PatchList;
32
use super::pointer::Pointer;
43
use super::string_block::StringBlock;
54
use crate::common::*;
5+
use crate::ser::Error;
66

77
#[derive(Clone, Copy)]
88
// The enum for current parsing type.

0 commit comments

Comments
 (0)