Skip to content

Commit

Permalink
serde: allow tracing-serde to work on no_std. (#960)
Browse files Browse the repository at this point in the history
Allows `tracing-serde` to work on devices without `std`.

*  Enable `#[no_std]` in `tracing-serde` when `cfg(not(feature = std))`
*  No longer have unnecessary dependencies on std in serde/tracing.

No behavior differences or actual code changes other than allowing
for core/alloc fallbacks.

Signed-off-by: Ana Hobden <[email protected]>
  • Loading branch information
Hoverbear authored Oct 1, 2020
1 parent 95d5511 commit 9c6dd2d
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 3 deletions.
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

0 comments on commit 9c6dd2d

Please sign in to comment.