Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

error in core changes #105

Merged
merged 2 commits into from
Jul 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ jobs:
- uses: actions-rs/cargo@v1
with:
command: test
args: --no-default-features --features ${{ matrix.feature }}
args: --no-default-features --features "std, ${{ matrix.feature }}"

no_std_features:
name: Test Individual Features NoStd
Expand All @@ -106,7 +106,7 @@ jobs:
- uses: actions-rs/cargo@v1
with:
command: test
args: --no-default-features --features "no_std, ${{ matrix.feature }}"
args: --no-default-features --features "${{ matrix.feature }}"

test:
name: Test
Expand Down Expand Up @@ -153,4 +153,4 @@ jobs:
- uses: actions-rs/cargo@v1
with:
command: test
args: --features "no_std"
args: --no-default-features --features "binary, json, ron, toml"
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ edition = "2018"
repository = "https://github.com/not-fl3/nanoserde"

[features]
default = ["json", "binary", "ron", "toml"]
default = ["json", "binary", "ron", "toml", "std"]
json = ["dep:nanoserde-derive", "nanoserde-derive/json"]
binary = ["dep:nanoserde-derive", "nanoserde-derive/binary"]
ron = ["dep:nanoserde-derive", "nanoserde-derive/ron"]
toml = []
no_std = []
std = []

[dependencies]
nanoserde-derive = { path = "derive", version = "=0.2.0", optional = true }
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down
1 change: 0 additions & 1 deletion derive/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,3 @@ default = []
json = []
binary = []
ron = []
no_std = []
2 changes: 1 addition & 1 deletion derive/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![cfg_attr(feature = "no_std", no_std)]
#![no_std]

extern crate alloc;
extern crate proc_macro;
Expand Down
18 changes: 11 additions & 7 deletions derive/src/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@
//! https://docs.rs/syn/0.15.44/syn/enum.Type.html
//! https://ziglang.org/documentation/0.5.0/#toc-typeInfo

use alloc::collections::BTreeSet;
use core::iter::Peekable;
use std::collections::HashSet;
use std::num::IntErrorKind;
use core::num::IntErrorKind;

use alloc::borrow::ToOwned;
use alloc::boxed::Box;
use alloc::string::{String, ToString};
use alloc::vec::Vec;
use alloc::{format, vec};
Expand All @@ -16,6 +18,7 @@

#[derive(Debug, Clone)]
pub struct Attribute {
#[allow(unused)]
pub name: String,
pub tokens: Vec<String>,
}
Expand All @@ -37,6 +40,7 @@
#[derive(Debug, Clone)]
pub struct Field {
pub attributes: Vec<Attribute>,
#[allow(unused)]
pub vis: Visibility,
pub field_name: Option<String>,
pub ty: Type,
Expand Down Expand Up @@ -131,7 +135,7 @@
pub named: bool,
pub fields: Vec<Field>,
pub attributes: Vec<Attribute>,
pub generics: Vec<Generic>,

Check warning on line 138 in derive/src/parse.rs

View workflow job for this annotation

GitHub Actions / Test Individual Features (ron)

field `generics` is never read

Check warning on line 138 in derive/src/parse.rs

View workflow job for this annotation

GitHub Actions / Test Individual Features NoStd (ron)

field `generics` is never read
}

#[derive(Debug)]
Expand All @@ -139,7 +143,7 @@
pub name: String,
pub variants: Vec<Field>,
pub attributes: Vec<Attribute>,
pub generics: Vec<Generic>,

Check warning on line 146 in derive/src/parse.rs

View workflow job for this annotation

GitHub Actions / Test Individual Features (ron)

field `generics` is never read

Check warning on line 146 in derive/src/parse.rs

View workflow job for this annotation

GitHub Actions / Test Individual Features NoStd (ron)

field `generics` is never read
}

#[allow(dead_code)]
Expand Down Expand Up @@ -1079,14 +1083,14 @@
(true, _) => {
attrs.push(Attribute {
name: name.clone(),
tokens: std::mem::take(&mut attr_tokens),
tokens: core::mem::take(&mut attr_tokens),
});
break;
}
(false, Some(",")) => {
attrs.push(Attribute {
name: name.clone(),
tokens: std::mem::take(&mut attr_tokens),
tokens: core::mem::take(&mut attr_tokens),
});
continue;
}
Expand All @@ -1105,14 +1109,14 @@
(true, _) => {
attrs.push(Attribute {
name: name.clone(),
tokens: std::mem::take(&mut attr_tokens),
tokens: core::mem::take(&mut attr_tokens),
});
break;
}
(false, true) => {
attrs.push(Attribute {
name: name.clone(),
tokens: std::mem::take(&mut attr_tokens),
tokens: core::mem::take(&mut attr_tokens),
});
}
_ => {}
Expand Down Expand Up @@ -1402,7 +1406,7 @@

fn get_all_bounds<T: Iterator<Item = TokenTree> + Clone>(source: &mut Peekable<T>) -> Vec<Generic> {
let mut ret = Vec::new();
let mut already = HashSet::new();
let mut already = BTreeSet::new();
if source.peek().map_or(false, |x| x.to_string() == "<") {
source.next();
} else {
Expand Down
6 changes: 5 additions & 1 deletion derive/src/shared.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
use alloc::string::String;
use alloc::{
format,

Check warning on line 2 in derive/src/shared.rs

View workflow job for this annotation

GitHub Actions / Test Individual Features (ron)

unused imports: `ToString`, `format`, `vec::Vec`

Check warning on line 2 in derive/src/shared.rs

View workflow job for this annotation

GitHub Actions / Test Individual Features NoStd (ron)

unused imports: `ToString`, `format`, and `vec::Vec`
string::{String, ToString},
vec::Vec,
};

#[cfg(any(feature = "binary", feature = "json"))]
use crate::parse::{Enum, Struct};
Expand Down
7 changes: 2 additions & 5 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,8 @@
//! `nanoserde` supports some serialization customisation with `#[nserde()]` attributes.
//! For `#[nserde(..)]` supported attributes for each format check [Features support matrix](https://github.com/not-fl3/nanoserde#features-support-matrix)

#![cfg_attr(feature = "no_std", no_std)]
// Possibly stable in 1.65.
// See: https://github.com/rust-lang/rust/pull/99917
// and https://github.com/rust-lang/rust/issues/103765
#![cfg_attr(feature = "no_std", feature(error_in_core))]
#![cfg_attr(not(feature = "std"), no_std)]
#![cfg_attr(not(feature = "std"), feature(error_in_core))]

Check warning on line 19 in src/lib.rs

View workflow job for this annotation

GitHub Actions / Test Individual Features NoStd (toml)

the feature `error_in_core` has been stable since 1.82.0-nightly and no longer requires an attribute to enable

Check warning on line 19 in src/lib.rs

View workflow job for this annotation

GitHub Actions / Test Individual Features NoStd (binary)

the feature `error_in_core` has been stable since 1.82.0-nightly and no longer requires an attribute to enable

Check warning on line 19 in src/lib.rs

View workflow job for this annotation

GitHub Actions / Test Individual Features NoStd (ron)

the feature `error_in_core` has been stable since 1.82.0-nightly and no longer requires an attribute to enable

Check warning on line 19 in src/lib.rs

View workflow job for this annotation

GitHub Actions / Test Individual Features NoStd (json)

the feature `error_in_core` has been stable since 1.82.0-nightly and no longer requires an attribute to enable

Check warning on line 19 in src/lib.rs

View workflow job for this annotation

GitHub Actions / Test No Std (ubuntu-latest, x86_64-unknown-linux-gnu)

the feature `error_in_core` has been stable since 1.82.0-nightly and no longer requires an attribute to enable

extern crate alloc;

Expand Down
20 changes: 11 additions & 9 deletions src/serde_bin.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand Down Expand Up @@ -77,11 +83,7 @@ impl core::fmt::Display for DeBinErr {
}
}

#[cfg(feature = "no_std")]
impl core::error::Error for DeBinErr {}

#[cfg(not(feature = "no_std"))]
impl std::error::Error for DeBinErr {}
impl Error for DeBinErr {}

macro_rules! impl_ser_de_bin_for {
($ty:ident) => {
Expand Down Expand Up @@ -287,7 +289,7 @@ where
}
}

#[cfg(not(feature = "no_std"))]
#[cfg(feature = "std")]
impl<T> SerBin for std::collections::HashSet<T>
where
T: SerBin,
Expand All @@ -301,7 +303,7 @@ where
}
}

#[cfg(not(feature = "no_std"))]
#[cfg(feature = "std")]
impl<T> DeBin for std::collections::HashSet<T>
where
T: DeBin + core::hash::Hash + Eq,
Expand Down Expand Up @@ -529,7 +531,7 @@ where
}
}

#[cfg(not(feature = "no_std"))]
#[cfg(feature = "std")]
impl<K, V> SerBin for std::collections::HashMap<K, V>
where
K: SerBin,
Expand All @@ -545,7 +547,7 @@ where
}
}

#[cfg(not(feature = "no_std"))]
#[cfg(feature = "std")]
impl<K, V> DeBin for std::collections::HashMap<K, V>
where
K: DeBin + core::cmp::Eq + core::hash::Hash,
Expand Down
20 changes: 11 additions & 9 deletions src/serde_json.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -160,11 +166,7 @@ impl core::fmt::Display for DeJsonErr {
}
}

#[cfg(feature = "no_std")]
impl core::error::Error for DeJsonErr {}

#[cfg(not(feature = "no_std"))]
impl std::error::Error for DeJsonErr {}
impl Error for DeJsonErr {}

impl DeJsonState {
pub fn next(&mut self, i: &mut Chars) {
Expand Down Expand Up @@ -878,7 +880,7 @@ where
}
}

#[cfg(not(feature = "no_std"))]
#[cfg(feature = "std")]
impl<T> SerJson for std::collections::HashSet<T>
where
T: SerJson,
Expand All @@ -899,7 +901,7 @@ where
}
}

#[cfg(not(feature = "no_std"))]
#[cfg(feature = "std")]
impl<T> DeJson for std::collections::HashSet<T>
where
T: DeJson + core::hash::Hash + Eq,
Expand Down Expand Up @@ -1172,7 +1174,7 @@ where
}
}

#[cfg(not(feature = "no_std"))]
#[cfg(feature = "std")]
impl<K, V> SerJson for std::collections::HashMap<K, V>
where
K: SerJson,
Expand All @@ -1197,7 +1199,7 @@ where
}
}

#[cfg(not(feature = "no_std"))]
#[cfg(feature = "std")]
impl<K, V> DeJson for std::collections::HashMap<K, V>
where
K: DeJson + Eq + core::hash::Hash,
Expand Down
20 changes: 11 additions & 9 deletions src/serde_ron.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -157,11 +163,7 @@ impl core::fmt::Display for DeRonErr {
}
}

#[cfg(feature = "no_std")]
impl core::error::Error for DeRonErr {}

#[cfg(not(feature = "no_std"))]
impl std::error::Error for DeRonErr {}
impl Error for DeRonErr {}

impl DeRonState {
pub fn next(&mut self, i: &mut Chars) {
Expand Down Expand Up @@ -876,7 +878,7 @@ where
}
}

#[cfg(not(feature = "no_std"))]
#[cfg(feature = "std")]
impl<T> SerRon for std::collections::HashSet<T>
where
T: SerRon,
Expand All @@ -897,7 +899,7 @@ where
}
}

#[cfg(not(feature = "no_std"))]
#[cfg(feature = "std")]
impl<T> DeRon for std::collections::HashSet<T>
where
T: DeRon + core::hash::Hash + Eq,
Expand Down Expand Up @@ -1184,7 +1186,7 @@ where
}
}

#[cfg(not(feature = "no_std"))]
#[cfg(feature = "std")]
impl<K, V> SerRon for std::collections::HashMap<K, V>
where
K: SerRon,
Expand All @@ -1204,7 +1206,7 @@ where
}
}

#[cfg(not(feature = "no_std"))]
#[cfg(feature = "std")]
impl<K, V> DeRon for std::collections::HashMap<K, V>
where
K: DeRon + Eq + core::hash::Hash,
Expand Down
12 changes: 7 additions & 5 deletions src/toml.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand Down Expand Up @@ -249,11 +255,7 @@ impl Out {
}
}

#[cfg(feature = "no_std")]
impl core::error::Error for TomlErr {}

#[cfg(not(feature = "no_std"))]
impl std::error::Error for TomlErr {}
impl Error for TomlErr {}

impl TomlParser {
/// Parse a TOML string.
Expand Down
6 changes: 4 additions & 2 deletions tests/json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use std::{
sync::atomic::AtomicBool,
};

#[cfg(not(feature = "no_std"))]
#[cfg(feature = "std")]
use std::collections::HashMap;

#[test]
Expand Down Expand Up @@ -69,6 +69,7 @@ fn de_multiline_comment() {
fn de_illegal_inline_comment() {
#[derive(DeJson)]
pub struct Test {
#[allow(unused)]
pub a: f32,
}

Expand All @@ -92,6 +93,7 @@ fn de_illegal_inline_comment() {
fn de_illegal_multiline_comment() {
#[derive(DeJson)]
pub struct Test {
#[allow(unused)]
pub a: f32,
}

Expand Down Expand Up @@ -467,7 +469,7 @@ fn path_type() {
assert_eq!(bar.d, Some(vec![vec![1, 2], vec![3, 4]]));
}

#[cfg(not(feature = "no_std"))]
#[cfg(feature = "std")]
#[test]
fn hashmaps() {
#[derive(DeJson)]
Expand Down
Loading
Loading