diff --git a/README.md b/README.md index c67121f..b16a57b 100644 --- a/README.md +++ b/README.md @@ -56,7 +56,7 @@ For more examples take a look at [tests](/tests) All features are enabled by default. To enable only specific formats, import nanoserde using ```toml -nanoserde = { version = "*", default-features = false, features = [] } +nanoserde = { version = "*", default-features = false, features = ["std", "{format feature name}"] } ``` in your `Cargo.toml` and add one or more of the following crate features: diff --git a/src/lib.rs b/src/lib.rs index 98c2778..501e803 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -16,6 +16,7 @@ //! For `#[nserde(..)]` supported attributes for each format check [Features support matrix](https://github.com/not-fl3/nanoserde#features-support-matrix) #![cfg_attr(not(feature = "std"), no_std)] +#![cfg_attr(not(feature = "std"), feature(error_in_core))] extern crate alloc; diff --git a/src/serde_bin.rs b/src/serde_bin.rs index c99e858..b0af507 100644 --- a/src/serde_bin.rs +++ b/src/serde_bin.rs @@ -1,5 +1,11 @@ use core::convert::TryInto; +// remove this after 1.81 is live +#[cfg(not(feature = "std"))] +use core::error::Error; +#[cfg(feature = "std")] +use std::error::Error; + use alloc::borrow::ToOwned; use alloc::boxed::Box; use alloc::collections::{BTreeMap, BTreeSet, LinkedList}; @@ -77,7 +83,7 @@ impl core::fmt::Display for DeBinErr { } } -impl core::error::Error for DeBinErr {} +impl Error for DeBinErr {} macro_rules! impl_ser_de_bin_for { ($ty:ident) => { diff --git a/src/serde_json.rs b/src/serde_json.rs index a10c63e..aba1dab 100644 --- a/src/serde_json.rs +++ b/src/serde_json.rs @@ -1,5 +1,11 @@ use core::str::Chars; +// remove this after 1.81 is live +#[cfg(not(feature = "std"))] +use core::error::Error; +#[cfg(feature = "std")] +use std::error::Error; + use alloc::boxed::Box; use alloc::collections::{BTreeMap, BTreeSet, LinkedList}; use alloc::format; @@ -160,7 +166,7 @@ impl core::fmt::Display for DeJsonErr { } } -impl core::error::Error for DeJsonErr {} +impl Error for DeJsonErr {} impl DeJsonState { pub fn next(&mut self, i: &mut Chars) { diff --git a/src/serde_ron.rs b/src/serde_ron.rs index f9b8677..2a4bbde 100644 --- a/src/serde_ron.rs +++ b/src/serde_ron.rs @@ -1,5 +1,11 @@ use core::str::Chars; +// remove this after 1.81 is live +#[cfg(not(feature = "std"))] +use core::error::Error; +#[cfg(feature = "std")] +use std::error::Error; + use alloc::boxed::Box; use alloc::collections::{BTreeMap, BTreeSet, LinkedList}; use alloc::format; @@ -157,7 +163,7 @@ impl core::fmt::Display for DeRonErr { } } -impl core::error::Error for DeRonErr {} +impl Error for DeRonErr {} impl DeRonState { pub fn next(&mut self, i: &mut Chars) { diff --git a/src/toml.rs b/src/toml.rs index 7d1fad6..1bd09ac 100644 --- a/src/toml.rs +++ b/src/toml.rs @@ -1,5 +1,11 @@ use core::str::Chars; +// remove this after 1.81 is live +#[cfg(not(feature = "std"))] +use core::error::Error; +#[cfg(feature = "std")] +use std::error::Error; + use alloc::format; use alloc::string::{String, ToString}; use alloc::{collections::BTreeMap, vec, vec::Vec}; @@ -249,7 +255,7 @@ impl Out { } } -impl core::error::Error for TomlErr {} +impl Error for TomlErr {} impl TomlParser { /// Parse a TOML string.