From 7dc65621b5b9dedcac281f926eb6acf0f1f9b72d Mon Sep 17 00:00:00 2001 From: Nicolas Lara Date: Fri, 27 Jan 2023 13:30:28 +0100 Subject: [PATCH 01/11] add default json schema implementation --- Cargo.toml | 9 +++++++++ src/lib.rs | 11 +++++++++++ 2 files changed, 20 insertions(+) diff --git a/Cargo.toml b/Cargo.toml index 9962372..befb0e1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,8 +10,17 @@ readme = "README.md" keywords = ["serde", "wasm"] license = "MIT" +[features] +json = ["json_schema"] + [dependencies] serde = "^1.0.0" +[dependencies.schemars] +version = "0.8.8" +default-features = false +features = ["json_schema"] + + [dev-dependencies] serde_derive = "^1.0.0" diff --git a/src/lib.rs b/src/lib.rs index fd291bd..57477b9 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -113,6 +113,17 @@ impl Ord for Value { } } +#[cfg(feature = "json_schema")] +impl JsonSchema for Value { + fn schema_name() -> String { + "JSON object".to_string() + } + + fn json_schema(gen: &mut schemars::gen::SchemaGenerator) -> schemars::schema::Schema { + schemars::schema::Schema::from(true) + } +} + impl Value { fn discriminant(&self) -> usize { match *self { From 7e1e492fab2ea9b3a266fdfff9670b37ef7a9f68 Mon Sep 17 00:00:00 2001 From: Nicolas Lara Date: Fri, 27 Jan 2023 13:40:48 +0100 Subject: [PATCH 02/11] fixes --- Cargo.toml | 9 ++------- src/lib.rs | 2 +- 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index befb0e1..085f100 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,16 +11,11 @@ keywords = ["serde", "wasm"] license = "MIT" [features] -json = ["json_schema"] +json_schema = [] [dependencies] serde = "^1.0.0" - -[dependencies.schemars] -version = "0.8.8" -default-features = false -features = ["json_schema"] - +schemars = { version = "0.8.11", default-features = false, cfg = "feature = \"json_schema\""} [dev-dependencies] serde_derive = "^1.0.0" diff --git a/src/lib.rs b/src/lib.rs index 57477b9..ff7a0f8 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -114,7 +114,7 @@ impl Ord for Value { } #[cfg(feature = "json_schema")] -impl JsonSchema for Value { +impl schemars::JsonSchema for Value { fn schema_name() -> String { "JSON object".to_string() } From 77e371d590b209c463b315e128407ed1c49f6374 Mon Sep 17 00:00:00 2001 From: Nicolas Lara Date: Fri, 27 Jan 2023 13:47:51 +0100 Subject: [PATCH 03/11] better name --- src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index ff7a0f8..76a289b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -116,7 +116,7 @@ impl Ord for Value { #[cfg(feature = "json_schema")] impl schemars::JsonSchema for Value { fn schema_name() -> String { - "JSON object".to_string() + "JSON".to_string() } fn json_schema(gen: &mut schemars::gen::SchemaGenerator) -> schemars::schema::Schema { From 00aebad37fc8cd79d1d827d6adc6a1106b49711d Mon Sep 17 00:00:00 2001 From: dzmitry-lahoda Date: Mon, 31 Jul 2023 16:07:45 +0100 Subject: [PATCH 04/11] no std and ibc-rs compat --- Cargo.toml | 13 ++++++++++--- src/lib.rs | 4 ++-- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 085f100..c710711 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,11 +11,18 @@ keywords = ["serde", "wasm"] license = "MIT" [features] -json_schema = [] +default = ["std"] + +std = [] +schema = ["std", "dep:schemars"] [dependencies] -serde = "^1.0.0" -schemars = { version = "0.8.11", default-features = false, cfg = "feature = \"json_schema\""} +serde = { version = "1.0.103", default-features = false, features = [ + "derive", + "alloc", +] } +schemars = { version = "0.8.3", optional = true } + [dev-dependencies] serde_derive = "^1.0.0" diff --git a/src/lib.rs b/src/lib.rs index 76a289b..85363f9 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -113,13 +113,13 @@ impl Ord for Value { } } -#[cfg(feature = "json_schema")] +#[cfg(feature = "schema")] impl schemars::JsonSchema for Value { fn schema_name() -> String { "JSON".to_string() } - fn json_schema(gen: &mut schemars::gen::SchemaGenerator) -> schemars::schema::Schema { + fn json_schema(_gen: &mut schemars::gen::SchemaGenerator) -> schemars::schema::Schema { schemars::schema::Schema::from(true) } } From fe16466caee886908645de5a8e0518dbac6d98df Mon Sep 17 00:00:00 2001 From: dzmitry-lahoda Date: Mon, 31 Jul 2023 16:24:00 +0100 Subject: [PATCH 05/11] same dep version as cw-std --- .gitignore | 1 - Cargo.lock | 142 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 142 insertions(+), 1 deletion(-) create mode 100644 Cargo.lock diff --git a/.gitignore b/.gitignore index 2c1d75e..15c17af 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,4 @@ /target/ -/Cargo.lock /.gitattributes /.idea/ *.iml diff --git a/Cargo.lock b/Cargo.lock new file mode 100644 index 0000000..b9d92f0 --- /dev/null +++ b/Cargo.lock @@ -0,0 +1,142 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "dyn-clone" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "304e6508efa593091e97a9abbc10f90aa7ca635b6d2784feff3c89d41dd12272" + +[[package]] +name = "itoa" +version = "1.0.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "af150ab688ff2122fcef229be89cb50dd66af9e01a4ff320cc137eecc9bacc38" + +[[package]] +name = "proc-macro2" +version = "1.0.66" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "18fb31db3f9bddb2ea821cde30a9f70117e3f119938b5ee630b7403aa6e2ead9" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "50f3b39ccfb720540debaa0164757101c08ecb8d326b15358ce76a62c7e85965" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "ryu" +version = "1.0.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1ad4cc8da4ef723ed60bced201181d83791ad433213d8c24efffda1eec85d741" + +[[package]] +name = "schemars" +version = "0.8.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "02c613288622e5f0c3fdc5dbd4db1c5fbe752746b1d1a56a0630b78fd00de44f" +dependencies = [ + "dyn-clone", + "schemars_derive", + "serde", + "serde_json", +] + +[[package]] +name = "schemars_derive" +version = "0.8.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "109da1e6b197438deb6db99952990c7f959572794b80ff93707d55a232545e7c" +dependencies = [ + "proc-macro2", + "quote", + "serde_derive_internals", + "syn 1.0.109", +] + +[[package]] +name = "serde" +version = "1.0.179" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0a5bf42b8d227d4abf38a1ddb08602e229108a517cd4e5bb28f9c7eaafdce5c0" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde-cw-value" +version = "0.7.0" +dependencies = [ + "schemars", + "serde", + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.179" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "741e124f5485c7e60c03b043f79f320bff3527f4bbf12cf3831750dc46a0ec2c" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.28", +] + +[[package]] +name = "serde_derive_internals" +version = "0.26.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85bf8229e7920a9f636479437026331ce11aa132b4dde37d121944a44d6e5f3c" +dependencies = [ + "proc-macro2", + "quote", + "syn 1.0.109", +] + +[[package]] +name = "serde_json" +version = "1.0.104" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "076066c5f1078eac5b722a31827a8832fe108bed65dfa75e233c89f8206e976c" +dependencies = [ + "itoa", + "ryu", + "serde", +] + +[[package]] +name = "syn" +version = "1.0.109" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "syn" +version = "2.0.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "04361975b3f5e348b2189d8dc55bc942f278b2d482a6a0365de5bdd62d351567" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "unicode-ident" +version = "1.0.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "301abaae475aa91687eb82514b328ab47a211a533026cb25fc3e519b86adfc3c" From 87bf7042d8f0766b3c322dbc94f2e703e206addc Mon Sep 17 00:00:00 2001 From: dzmitry-lahoda Date: Wed, 2 Aug 2023 23:28:18 +0100 Subject: [PATCH 06/11] fixes --- src/lib.rs | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 85363f9..6ef8cf7 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,7 +1,24 @@ +#![cfg_attr(not(feature = "std"), no_std)] use serde::Deserialize; -use std::cmp::Ordering; -use std::collections::BTreeMap; -use std::hash::{Hash, Hasher}; + +#[cfg(feature = "std")] +use std::{ + cmp::Ordering, + collections::BTreeMap, + hash::{Hash, Hasher}, + vec::Vec, +}; + +#[cfg(not(feature = "std"))] +extern crate alloc; + +#[cfg(not(feature = "std"))] +use alloc::{collections::BTreeMap, vec::Vec}; +#[cfg(not(feature = "std"))] +use core::{ + cmp::Ordering, + hash::{Hash, Hasher}, +}; pub use de::*; pub use ser::*; From 144d888492c19a7a975e7d597c4bb4f0ef9b0a39 Mon Sep 17 00:00:00 2001 From: dzmitry-lahoda Date: Wed, 2 Aug 2023 23:31:07 +0100 Subject: [PATCH 07/11] boxed --- src/lib.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index 6ef8cf7..2b878bb 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -3,6 +3,7 @@ use serde::Deserialize; #[cfg(feature = "std")] use std::{ + boxed::Box, cmp::Ordering, collections::BTreeMap, hash::{Hash, Hasher}, @@ -13,7 +14,7 @@ use std::{ extern crate alloc; #[cfg(not(feature = "std"))] -use alloc::{collections::BTreeMap, vec::Vec}; +use alloc::{boxed::Box, collections::BTreeMap, vec::Vec}; #[cfg(not(feature = "std"))] use core::{ cmp::Ordering, From 03a588ff67e40006b77fbfaa66404d02e511275c Mon Sep 17 00:00:00 2001 From: dzmitry-lahoda Date: Wed, 2 Aug 2023 23:32:05 +0100 Subject: [PATCH 08/11] oh --- src/lib.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index 2b878bb..a78e858 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -7,6 +7,7 @@ use std::{ cmp::Ordering, collections::BTreeMap, hash::{Hash, Hasher}, + string::String, vec::Vec, }; @@ -14,7 +15,7 @@ use std::{ extern crate alloc; #[cfg(not(feature = "std"))] -use alloc::{boxed::Box, collections::BTreeMap, vec::Vec}; +use alloc::{boxed::Box, collections::BTreeMap, string::String, vec::Vec}; #[cfg(not(feature = "std"))] use core::{ cmp::Ordering, From 14b9eedb11d1dd89960b35d60daec928d7edcb52 Mon Sep 17 00:00:00 2001 From: dzmitry-lahoda Date: Wed, 2 Aug 2023 23:36:03 +0100 Subject: [PATCH 09/11] happy std --- src/de.rs | 8 ++------ src/lib.rs | 21 +++------------------ src/no_std.rs | 23 +++++++++++++++++++++++ src/ser.rs | 7 ++----- 4 files changed, 30 insertions(+), 29 deletions(-) create mode 100644 src/no_std.rs diff --git a/src/de.rs b/src/de.rs index c846cb7..2d8b21f 100644 --- a/src/de.rs +++ b/src/de.rs @@ -1,10 +1,6 @@ -use serde::{de, forward_to_deserialize_any}; -use std::collections::BTreeMap; -use std::error::Error; -use std::fmt; -use std::marker::PhantomData; - +use crate::no_std::*; use crate::Value; +use serde::{de, forward_to_deserialize_any}; #[derive(Debug)] pub enum Unexpected { diff --git a/src/lib.rs b/src/lib.rs index a78e858..5298d87 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,31 +1,16 @@ #![cfg_attr(not(feature = "std"), no_std)] -use serde::Deserialize; - -#[cfg(feature = "std")] -use std::{ - boxed::Box, - cmp::Ordering, - collections::BTreeMap, - hash::{Hash, Hasher}, - string::String, - vec::Vec, -}; #[cfg(not(feature = "std"))] extern crate alloc; -#[cfg(not(feature = "std"))] -use alloc::{boxed::Box, collections::BTreeMap, string::String, vec::Vec}; -#[cfg(not(feature = "std"))] -use core::{ - cmp::Ordering, - hash::{Hash, Hasher}, -}; +use crate::no_std::*; +use serde::Deserialize; pub use de::*; pub use ser::*; mod de; +mod no_std; mod ser; #[derive(Clone, Debug)] diff --git a/src/no_std.rs b/src/no_std.rs new file mode 100644 index 0000000..ab30932 --- /dev/null +++ b/src/no_std.rs @@ -0,0 +1,23 @@ +#[cfg(feature = "std")] +pub use std::{ + boxed::Box, + cmp::Ordering, + collections::BTreeMap, + error::Error, + fmt, + hash::{Hash, Hasher}, + marker::PhantomData, + string::String, + vec::Vec, +}; + +#[cfg(not(feature = "std"))] +pub use alloc::{boxed::Box, collections::BTreeMap, string::String, vec::Vec}; +#[cfg(not(feature = "std"))] +pub use core::{ + cmp::Ordering, + error::Error, + fmt, + hash::{Hash, Hasher}, + marker::PhantomData, +}; diff --git a/src/ser.rs b/src/ser.rs index 9dcbdcb..164895e 100644 --- a/src/ser.rs +++ b/src/ser.rs @@ -1,9 +1,6 @@ -use serde::ser; -use std::collections::BTreeMap; -use std::error::Error; -use std::fmt; - +use crate::no_std::*; use crate::Value; +use serde::ser; #[derive(Debug)] pub enum SerializerError { From c8ae519474d0a81896bc7b3409990f5ce85aa86e Mon Sep 17 00:00:00 2001 From: dzmitry-lahoda Date: Wed, 2 Aug 2023 23:37:36 +0100 Subject: [PATCH 10/11] ohooh' --- src/no_std.rs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/no_std.rs b/src/no_std.rs index ab30932..308bf78 100644 --- a/src/no_std.rs +++ b/src/no_std.rs @@ -8,11 +8,19 @@ pub use std::{ hash::{Hash, Hasher}, marker::PhantomData, string::String, + string::{String, ToString}, + vec, vec::Vec, }; #[cfg(not(feature = "std"))] -pub use alloc::{boxed::Box, collections::BTreeMap, string::String, vec::Vec}; +pub use alloc::{ + boxed::Box, + collections::BTreeMap, + string::{String, ToString}, + vec, + vec::Vec, +}; #[cfg(not(feature = "std"))] pub use core::{ cmp::Ordering, From b91ac6d797fd24c00758ad3995a55dc820279595 Mon Sep 17 00:00:00 2001 From: dzmitry-lahoda Date: Wed, 2 Aug 2023 23:39:37 +0100 Subject: [PATCH 11/11] yeah --- src/lib.rs | 1 + src/no_std.rs | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index 5298d87..45326f5 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,4 +1,5 @@ #![cfg_attr(not(feature = "std"), no_std)] +#![feature(error_in_core)] #[cfg(not(feature = "std"))] extern crate alloc; diff --git a/src/no_std.rs b/src/no_std.rs index 308bf78..b003d85 100644 --- a/src/no_std.rs +++ b/src/no_std.rs @@ -1,5 +1,6 @@ #[cfg(feature = "std")] pub use std::{ + borrow::ToOwned, boxed::Box, cmp::Ordering, collections::BTreeMap, @@ -7,7 +8,6 @@ pub use std::{ fmt, hash::{Hash, Hasher}, marker::PhantomData, - string::String, string::{String, ToString}, vec, vec::Vec, @@ -15,6 +15,7 @@ pub use std::{ #[cfg(not(feature = "std"))] pub use alloc::{ + borrow::ToOwned, boxed::Box, collections::BTreeMap, string::{String, ToString},