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

Allow tracing-serde to work on no_std. #960

Merged
merged 5 commits into from
Oct 1, 2020
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
8 changes: 6 additions & 2 deletions tracing-serde/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,13 @@ categories = [
]
keywords = ["logging", "tracing", "serialization"]

[features]
default = ["std"]
std = ["serde/std", "tracing-core/std"]

[dependencies]
serde = "1"
tracing-core = { path = "../tracing-core", version = "0.2"}
serde = { version = "1", default-features = false, features = ["alloc"] }
tracing-core = { path = "../tracing-core", version = "0.2", default-features = false }

[dev-dependencies]
serde_json = "1"
Expand Down
16 changes: 16 additions & 0 deletions tracing-serde/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,22 @@ After you implement your `Subscriber`, you can use your `tracing`
subscriber (`JsonSubscriber` in the above example) to record serialized
trace data.

## Crate Feature Flags

The following crate feature flags are available:

* `std`: Depend on the Rust standard library (enabled by default).

`no_std` users may disable this feature with `default-features = false`:

```toml
[dependencies]
tracing-serde = { version = "0.2", default-features = false }
```

**Note**:`tracing-serde`'s `no_std` support requires `liballoc`.


## Supported Rust Versions

Tracing is built against the latest stable release. The minimum supported
Expand Down
20 changes: 19 additions & 1 deletion tracing-serde/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,21 @@
//! subscriber (`JsonSubscriber` in the above example) to record serialized
//! trace data.
//!
//! ## Crate Feature Flags
//!
//! The following crate feature flags are available:
//!
//! * `std`: Depend on the Rust standard library (enabled by default).
//!
//! `no_std` users may disable this feature with `default-features = false`:
//!
//! ```toml
//! [dependencies]
//! tracing-serde = { version = "0.2", default-features = false }
//! ```
//
//! **Note**:`tracing-serde`'s `no_std` support requires `liballoc`.
//!
//! ## Supported Rust Versions
//!
//! Tracing is built against the latest stable release. The minimum supported
Expand Down Expand Up @@ -153,7 +168,10 @@
unused_parens,
while_true
)]
use std::fmt;
// Support using tracing-serde without the standard library!
#![cfg_attr(not(feature = "std"), no_std)]

use core::fmt;

use serde::{
ser::{SerializeMap, SerializeSeq, SerializeStruct, SerializeTupleStruct, Serializer},
Expand Down