From d917c549470ae409fa407622c2f2f138bf46c407 Mon Sep 17 00:00:00 2001 From: Ahmed Charles <acharles@outlook.com> Date: Sat, 21 Mar 2020 20:00:42 +0000 Subject: [PATCH] Create a workspace with serde_cbor as a member. --- .gitignore | 1 - .travis.yml | 10 +-- Cargo.toml | 35 +-------- README.md | 67 +---------------- serde_cbor/.gitignore | 1 + serde_cbor/Cargo.toml | 35 +++++++++ serde_cbor/README.md | 79 ++++++++++++++++++++ {examples => serde_cbor/examples}/readme.rs | 0 {examples => serde_cbor/examples}/tags.rs | 0 {examples => serde_cbor/examples}/tux.cbor | 0 {src => serde_cbor/src}/de.rs | 0 {src => serde_cbor/src}/error.rs | 0 {src => serde_cbor/src}/lib.rs | 4 +- {src => serde_cbor/src}/read.rs | 0 {src => serde_cbor/src}/ser.rs | 0 {src => serde_cbor/src}/tags.rs | 3 +- {src => serde_cbor/src}/value/de.rs | 0 {src => serde_cbor/src}/value/mod.rs | 0 {src => serde_cbor/src}/value/ser.rs | 0 {src => serde_cbor/src}/write.rs | 0 {tests => serde_cbor/tests}/bennofs.rs | 0 {tests => serde_cbor/tests}/canonical.rs | 0 {tests => serde_cbor/tests}/crash.cbor | Bin {tests => serde_cbor/tests}/de.rs | 0 {tests => serde_cbor/tests}/enum.rs | 0 {tests => serde_cbor/tests}/kietaub.cbor | Bin {tests => serde_cbor/tests}/ser.rs | 0 {tests => serde_cbor/tests}/std_types.rs | 2 +- {tests => serde_cbor/tests}/tags.rs | 0 {tests => serde_cbor/tests}/value.rs | 2 +- 30 files changed, 131 insertions(+), 108 deletions(-) create mode 100644 serde_cbor/.gitignore create mode 100644 serde_cbor/Cargo.toml create mode 100644 serde_cbor/README.md rename {examples => serde_cbor/examples}/readme.rs (100%) rename {examples => serde_cbor/examples}/tags.rs (100%) rename {examples => serde_cbor/examples}/tux.cbor (100%) rename {src => serde_cbor/src}/de.rs (100%) rename {src => serde_cbor/src}/error.rs (100%) rename {src => serde_cbor/src}/lib.rs (99%) rename {src => serde_cbor/src}/read.rs (100%) rename {src => serde_cbor/src}/ser.rs (100%) rename {src => serde_cbor/src}/tags.rs (99%) rename {src => serde_cbor/src}/value/de.rs (100%) rename {src => serde_cbor/src}/value/mod.rs (100%) rename {src => serde_cbor/src}/value/ser.rs (100%) rename {src => serde_cbor/src}/write.rs (100%) rename {tests => serde_cbor/tests}/bennofs.rs (100%) rename {tests => serde_cbor/tests}/canonical.rs (100%) rename {tests => serde_cbor/tests}/crash.cbor (100%) rename {tests => serde_cbor/tests}/de.rs (100%) rename {tests => serde_cbor/tests}/enum.rs (100%) rename {tests => serde_cbor/tests}/kietaub.cbor (100%) rename {tests => serde_cbor/tests}/ser.rs (100%) rename {tests => serde_cbor/tests}/std_types.rs (99%) rename {tests => serde_cbor/tests}/tags.rs (100%) rename {tests => serde_cbor/tests}/value.rs (98%) diff --git a/.gitignore b/.gitignore index 4cc3f225..46108505 100644 --- a/.gitignore +++ b/.gitignore @@ -4,5 +4,4 @@ Cargo.lock tokamak.toml .idea *.iml -examples/ferris.cbor .cargo/config diff --git a/.travis.yml b/.travis.yml index a3ce2365..2467ccf3 100644 --- a/.travis.yml +++ b/.travis.yml @@ -18,11 +18,11 @@ script: - cargo test - > [[ $TRAVIS_RUST_VERSION == "1.31.0" ]] - || cargo build --no-default-features --features alloc --target thumbv7em-none-eabihf + || cargo build --no-default-features --features alloc --target thumbv7em-none-eabihf --manifest-path serde_cbor/Cargo.toml # Test we can build a platform that does not have std. - - cargo test --no-default-features --lib --tests # Run no_std tests + - cargo test --no-default-features --lib --tests --manifest-path serde_cbor/Cargo.toml # Run no_std tests - > [[ $TRAVIS_RUST_VERSION == "1.31.0" ]] - || cargo build --no-default-features --features alloc - - cargo build --features unsealed_read_write # The crate should still build when the unsealed_read_write feature is enabled. - - cargo build --no-default-features --features unsealed_read_write # The crate should still build when the unsealed_read_write feature is enabled and std disabled. + || cargo build --no-default-features --features alloc --manifest-path serde_cbor/Cargo.toml + - cargo build --features unsealed_read_write --manifest-path serde_cbor/Cargo.toml # The crate should still build when the unsealed_read_write feature is enabled. + - cargo build --no-default-features --features unsealed_read_write --manifest-path serde_cbor/Cargo.toml # The crate should still build when the unsealed_read_write feature is enabled and std disabled. diff --git a/Cargo.toml b/Cargo.toml index 8b5c14c4..5097b53a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,33 +1,2 @@ -[package] -name = "serde_cbor" -version = "0.11.1" -authors = [ - "Pyfisch <pyfisch@gmail.com>", - "Steven Fackler <sfackler@gmail.com>"] -repository = "https://github.com/pyfisch/cbor" -readme = "README.md" -license = "MIT/Apache-2.0" -description = "CBOR support for serde." -keywords = ["serde", "cbor", "serialization", "no_std"] -categories = ["encoding"] -edition = "2018" - -[badges] -travis-ci = { repository = "pyfisch/cbor" } -maintenance = { status = "passively-maintained" } - -[dependencies] -half = "1.2.0" -serde = { version = "1.0.14", default-features = false } - -[dev-dependencies] -serde_derive = { version = "1.0.14", default-features = false } - -[features] -default = ["std"] -# Uses `alloc` library and adds support for vector functions with -# `no_std`. -alloc = ["serde/alloc"] -std = ["serde/std" ] -unsealed_read_write = [] -tags = [] +[workspace] +members = ["serde_cbor"] diff --git a/README.md b/README.md index 56246918..cae92115 100644 --- a/README.md +++ b/README.md @@ -1,69 +1,10 @@ # Serde CBOR [](https://travis-ci.org/pyfisch/cbor) -[](https://crates.io/crates/serde_cbor) -[](https://docs.rs/serde_cbor) +[](https://crates.io/crates/serde_cbor) +[](https://docs.rs/serde_cbor) -This crate implements the Concise Binary Object Representation from [RFC 7049]. -It builds on [Serde], the generic serialization framework for Rust. -CBOR provides a binary encoding for a superset -of the JSON data model that is small and very fast to parse. - -[RFC 7049]: https://tools.ietf.org/html/rfc7049 -[Serde]: https://github.com/serde-rs/serde - -## Usage - -Serde CBOR supports Rust 1.40 and up. Add this to your `Cargo.toml`: -```toml -[dependencies] -serde_cbor = "0.11.1" -``` - -Storing and loading Rust types is easy and requires only -minimal modifications to the program code. - -```rust -use serde_derive::{Deserialize, Serialize}; -use std::error::Error; -use std::fs::File; - -// Types annotated with `Serialize` can be stored as CBOR. -// To be able to load them again add `Deserialize`. -#[derive(Debug, Serialize, Deserialize)] -struct Mascot { - name: String, - species: String, - year_of_birth: u32, -} - -fn main() -> Result<(), Box<dyn Error>> { - let ferris = Mascot { - name: "Ferris".to_owned(), - species: "crab".to_owned(), - year_of_birth: 2015, - }; - - let ferris_file = File::create("examples/ferris.cbor")?; - // Write Ferris to the given file. - // Instead of a file you can use any type that implements `io::Write` - // like a HTTP body, database connection etc. - serde_cbor::to_writer(ferris_file, &ferris)?; - - let tux_file = File::open("examples/tux.cbor")?; - // Load Tux from a file. - // Serde CBOR performs roundtrip serialization meaning that - // the data will not change in any way. - let tux: Mascot = serde_cbor::from_reader(tux_file)?; - - println!("{:?}", tux); - // prints: Mascot { name: "Tux", species: "penguin", year_of_birth: 1996 } - - Ok(()) -} -``` - -There are a lot of options available to customize the format. -To operate on untyped CBOR values have a look at the `Value` type. +This repository implements the Concise Binary Object Representation from +[RFC 7049]. It contains the `serde_cbor` crate. ## License Licensed under either of diff --git a/serde_cbor/.gitignore b/serde_cbor/.gitignore new file mode 100644 index 00000000..d72df11e --- /dev/null +++ b/serde_cbor/.gitignore @@ -0,0 +1 @@ +examples/ferris.cbor diff --git a/serde_cbor/Cargo.toml b/serde_cbor/Cargo.toml new file mode 100644 index 00000000..2e18903e --- /dev/null +++ b/serde_cbor/Cargo.toml @@ -0,0 +1,35 @@ +[package] +name = "serde_cbor" +version = "0.12.0" +authors = [ + "Pyfisch <pyfisch@gmail.com>", + "Steven Fackler <sfackler@gmail.com>", +] +repository = "https://github.com/pyfisch/cbor" +readme = "README.md" +license = "MIT/Apache-2.0" +description = "CBOR support for serde." +keywords = ["serde", "cbor", "serialization", "no_std"] +categories = ["encoding"] +edition = "2018" +workspace = ".." + +[badges] +travis-ci = { repository = "pyfisch/cbor" } +maintenance = { status = "passively-maintained" } + +[dependencies] +half = "1.2.0" +serde = { version = "1.0.14", default-features = false } + +[dev-dependencies] +serde_derive = { version = "1.0.14", default-features = false } + +[features] +default = ["std"] +# Uses `alloc` library and adds support for vector functions with +# `no_std`. +alloc = ["serde/alloc"] +std = ["serde/std" ] +unsealed_read_write = [] +tags = [] diff --git a/serde_cbor/README.md b/serde_cbor/README.md new file mode 100644 index 00000000..6a00af17 --- /dev/null +++ b/serde_cbor/README.md @@ -0,0 +1,79 @@ +# Serde CBOR +[](https://travis-ci.org/pyfisch/cbor) +[](https://crates.io/crates/serde_cbor) +[](https://docs.rs/serde_cbor) + +This crate implements the Concise Binary Object Representation from [RFC 7049]. +It builds on [Serde], the generic serialization framework for Rust. +CBOR provides a binary encoding for a superset +of the JSON data model that is small and very fast to parse. + +[RFC 7049]: https://tools.ietf.org/html/rfc7049 +[Serde]: https://github.com/serde-rs/serde + +## Usage + +Serde CBOR supports Rust 1.40 and up. Add this to your `Cargo.toml`: +```toml +[dependencies] +serde_cbor = "0.12.0" +``` + +Storing and loading Rust types is easy and requires only +minimal modifications to the program code. + +```rust +use serde_derive::{Deserialize, Serialize}; +use std::error::Error; +use std::fs::File; + +// Types annotated with `Serialize` can be stored as CBOR. +// To be able to load them again add `Deserialize`. +#[derive(Debug, Serialize, Deserialize)] +struct Mascot { + name: String, + species: String, + year_of_birth: u32, +} + +fn main() -> Result<(), Box<dyn Error>> { + let ferris = Mascot { + name: "Ferris".to_owned(), + species: "crab".to_owned(), + year_of_birth: 2015, + }; + + let ferris_file = File::create("examples/ferris.cbor")?; + // Write Ferris to the given file. + // Instead of a file you can use any type that implements `io::Write` + // like a HTTP body, database connection etc. + serde_cbor::to_writer(ferris_file, &ferris)?; + + let tux_file = File::open("examples/tux.cbor")?; + // Load Tux from a file. + // Serde CBOR performs roundtrip serialization meaning that + // the data will not change in any way. + let tux: Mascot = serde_cbor::from_reader(tux_file)?; + + println!("{:?}", tux); + // prints: Mascot { name: "Tux", species: "penguin", year_of_birth: 1996 } + + Ok(()) +} +``` + +There are a lot of options available to customize the format. +To operate on untyped CBOR values have a look at the `Value` type. + +## License +Licensed under either of + + * Apache License, Version 2.0 ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0) + * MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT) + +at your option. + +### Contribution +Unless you explicitly state otherwise, any contribution intentionally submitted +for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any +additional terms or conditions. diff --git a/examples/readme.rs b/serde_cbor/examples/readme.rs similarity index 100% rename from examples/readme.rs rename to serde_cbor/examples/readme.rs diff --git a/examples/tags.rs b/serde_cbor/examples/tags.rs similarity index 100% rename from examples/tags.rs rename to serde_cbor/examples/tags.rs diff --git a/examples/tux.cbor b/serde_cbor/examples/tux.cbor similarity index 100% rename from examples/tux.cbor rename to serde_cbor/examples/tux.cbor diff --git a/src/de.rs b/serde_cbor/src/de.rs similarity index 100% rename from src/de.rs rename to serde_cbor/src/de.rs diff --git a/src/error.rs b/serde_cbor/src/error.rs similarity index 100% rename from src/error.rs rename to serde_cbor/src/error.rs diff --git a/src/lib.rs b/serde_cbor/src/lib.rs similarity index 99% rename from src/lib.rs rename to serde_cbor/src/lib.rs index 55668541..a754dce5 100644 --- a/src/lib.rs +++ b/serde_cbor/src/lib.rs @@ -5,7 +5,7 @@ //! Serde CBOR supports Rust 1.40 and up. Add this to your `Cargo.toml`: //! ```toml //! [dependencies] -//! serde_cbor = "0.10" +//! serde_cbor = "0.12" //! ``` //! //! Storing and loading Rust types is easy and requires only @@ -197,7 +197,7 @@ //! ``` toml //! [dependencies] //! serde = { version = "1.0", default-features = false } -//! serde_cbor = { version = "0.10", default-features = false } +//! serde_cbor = { version = "0.12", default-features = false } //! ``` //! //! Without the `std` feature the functions [from_reader], [from_slice], [to_vec], and [to_writer] diff --git a/src/read.rs b/serde_cbor/src/read.rs similarity index 100% rename from src/read.rs rename to serde_cbor/src/read.rs diff --git a/src/ser.rs b/serde_cbor/src/ser.rs similarity index 100% rename from src/ser.rs rename to serde_cbor/src/ser.rs diff --git a/src/tags.rs b/serde_cbor/src/tags.rs similarity index 99% rename from src/tags.rs rename to serde_cbor/src/tags.rs index 50e039e7..8adccb8e 100644 --- a/src/tags.rs +++ b/serde_cbor/src/tags.rs @@ -42,8 +42,7 @@ fn untagged<T>(value: T) -> Tagged<T> { macro_rules! delegate { ($name: ident, $type: ty) => { - fn $name<E: serde::de::Error>(self, v: $type) -> Result<Self::Value, E> - { + fn $name<E: serde::de::Error>(self, v: $type) -> Result<Self::Value, E> { T::deserialize(v.into_deserializer()).map(untagged) } }; diff --git a/src/value/de.rs b/serde_cbor/src/value/de.rs similarity index 100% rename from src/value/de.rs rename to serde_cbor/src/value/de.rs diff --git a/src/value/mod.rs b/serde_cbor/src/value/mod.rs similarity index 100% rename from src/value/mod.rs rename to serde_cbor/src/value/mod.rs diff --git a/src/value/ser.rs b/serde_cbor/src/value/ser.rs similarity index 100% rename from src/value/ser.rs rename to serde_cbor/src/value/ser.rs diff --git a/src/write.rs b/serde_cbor/src/write.rs similarity index 100% rename from src/write.rs rename to serde_cbor/src/write.rs diff --git a/tests/bennofs.rs b/serde_cbor/tests/bennofs.rs similarity index 100% rename from tests/bennofs.rs rename to serde_cbor/tests/bennofs.rs diff --git a/tests/canonical.rs b/serde_cbor/tests/canonical.rs similarity index 100% rename from tests/canonical.rs rename to serde_cbor/tests/canonical.rs diff --git a/tests/crash.cbor b/serde_cbor/tests/crash.cbor similarity index 100% rename from tests/crash.cbor rename to serde_cbor/tests/crash.cbor diff --git a/tests/de.rs b/serde_cbor/tests/de.rs similarity index 100% rename from tests/de.rs rename to serde_cbor/tests/de.rs diff --git a/tests/enum.rs b/serde_cbor/tests/enum.rs similarity index 100% rename from tests/enum.rs rename to serde_cbor/tests/enum.rs diff --git a/tests/kietaub.cbor b/serde_cbor/tests/kietaub.cbor similarity index 100% rename from tests/kietaub.cbor rename to serde_cbor/tests/kietaub.cbor diff --git a/tests/ser.rs b/serde_cbor/tests/ser.rs similarity index 100% rename from tests/ser.rs rename to serde_cbor/tests/ser.rs diff --git a/tests/std_types.rs b/serde_cbor/tests/std_types.rs similarity index 99% rename from tests/std_types.rs rename to serde_cbor/tests/std_types.rs index 7a7ded48..a26a634b 100644 --- a/tests/std_types.rs +++ b/serde_cbor/tests/std_types.rs @@ -1,4 +1,4 @@ -#[macro_use] +#[cfg_attr(feature = "std", macro_use)] extern crate serde_derive; #[cfg(feature = "std")] diff --git a/tests/tags.rs b/serde_cbor/tests/tags.rs similarity index 100% rename from tests/tags.rs rename to serde_cbor/tests/tags.rs diff --git a/tests/value.rs b/serde_cbor/tests/value.rs similarity index 98% rename from tests/value.rs rename to serde_cbor/tests/value.rs index 554d7426..ac29d3ae 100644 --- a/tests/value.rs +++ b/serde_cbor/tests/value.rs @@ -1,4 +1,4 @@ -#[macro_use] +#[cfg_attr(feature = "std", macro_use)] extern crate serde_derive; #[cfg(feature = "std")]