Skip to content
This repository has been archived by the owner on Aug 15, 2021. It is now read-only.

Create a workspace with serde_cbor as a member. #184

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,4 @@ Cargo.lock
tokamak.toml
.idea
*.iml
examples/ferris.cbor
.cargo/config
10 changes: 5 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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.
35 changes: 2 additions & 33 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,33 +1,2 @@
[package]
name = "serde_cbor"
version = "0.11.1"
authors = [
"Pyfisch <[email protected]>",
"Steven Fackler <[email protected]>"]
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"]
67 changes: 4 additions & 63 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,69 +1,10 @@
# Serde CBOR
[![Build Status](https://travis-ci.org/pyfisch/cbor.svg?branch=master)](https://travis-ci.org/pyfisch/cbor)
[![Crates.io](https://img.shields.io/crates/v/serde_cbor.svg)](https://crates.io/crates/serde_cbor)
[![Documentation](https://docs.rs/serde_cbor/badge.svg)](https://docs.rs/serde_cbor)
[![Serde CBOR Crates.io](https://img.shields.io/crates/v/serde_cbor.svg)](https://crates.io/crates/serde_cbor)
[![Serde CBOR Documentation](https://docs.rs/serde_cbor/badge.svg)](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
Expand Down
1 change: 1 addition & 0 deletions serde_cbor/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
examples/ferris.cbor
35 changes: 35 additions & 0 deletions serde_cbor/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
[package]
name = "serde_cbor"
version = "0.12.0"
authors = [
"Pyfisch <[email protected]>",
"Steven Fackler <[email protected]>",
]
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 = []
79 changes: 79 additions & 0 deletions serde_cbor/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
# Serde CBOR
[![Build Status](https://travis-ci.org/pyfisch/cbor.svg?branch=master)](https://travis-ci.org/pyfisch/cbor)
[![Crates.io](https://img.shields.io/crates/v/serde_cbor.svg)](https://crates.io/crates/serde_cbor)
[![Documentation](https://docs.rs/serde_cbor/badge.svg)](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.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions src/lib.rs → serde_cbor/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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]
Expand Down
File renamed without changes.
File renamed without changes.
3 changes: 1 addition & 2 deletions src/tags.rs → serde_cbor/src/tags.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
};
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion tests/std_types.rs → serde_cbor/tests/std_types.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#[macro_use]
#[cfg_attr(feature = "std", macro_use)]
extern crate serde_derive;

#[cfg(feature = "std")]
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion tests/value.rs → serde_cbor/tests/value.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#[macro_use]
#[cfg_attr(feature = "std", macro_use)]
extern crate serde_derive;

#[cfg(feature = "std")]
Expand Down