Eliza Weisman 2572f68339
core: support no-std + alloc (#256)
* core: support `no-std` + `alloc`

Motivation

Users have expressed interest in using `tracing` on no_std platforms
with `liballoc`.

Solution

This branch adds `no_std` support to `tracing-core` by adding a `std`
feature flag (on by default) which can be disabled to use `libcore` +
`liballoc` instead of `libstd`.

When the `std` feature is disabled, `tracing-core` will use
`spin::Mutex` rather than `std::sync::Mutex`, and the thread-local
scoped dispatcher will be disabled (since it necessitates a defined OS
threading model, which may not exist on `no_std` platforms).

Refs: #213

Signed-off-by: Eliza Weisman <eliza@buoyant.io>
2019-08-09 13:27:35 -07:00

49 lines
1.2 KiB
Rust

use tracing_core::{
callsite::Callsite,
metadata,
metadata::{Kind, Level, Metadata},
subscriber::Interest,
};
#[test]
fn metadata_macro_api() {
// This test should catch any inadvertent breaking changes
// caused by changes to the macro.
struct TestCallsite;
impl Callsite for TestCallsite {
fn set_interest(&self, _: Interest) {
unimplemented!("test")
}
fn metadata(&self) -> &Metadata<'_> {
unimplemented!("test")
}
}
static CALLSITE: TestCallsite = TestCallsite;
let _metadata = metadata! {
name: "test_metadata",
target: "test_target",
level: Level::DEBUG,
fields: &["foo", "bar", "baz"],
callsite: &CALLSITE,
kind: Kind::SPAN,
};
let _metadata = metadata! {
name: "test_metadata",
target: "test_target",
level: Level::TRACE,
fields: &[],
callsite: &CALLSITE,
kind: Kind::EVENT,
};
let _metadata = metadata! {
name: "test_metadata",
target: "test_target",
level: Level::INFO,
fields: &[],
callsite: &CALLSITE,
kind: Kind::EVENT
};
}