mirror of
https://github.com/eyre-rs/eyre.git
synced 2025-09-28 05:21:34 +00:00

RFC 2145 is in beta now, deprecating the public_in_private lint. https://rust-lang.github.io/rfcs/2145-type-privacy.html public_in_private has been superceded by three new lints. The first two are warn-by-default and the third is allow-by-default. See the excerpt below for some details. This change skips this lint in nightly and beta in favor of the new warn-by-default lints. This change revealed a bug in the toolchain config option for color-spantrace -- it doesn't exist! The lint it was guarding was never turned on. This adds a minimal build script to check for toolchain to color-spantrace. Its functionality is tested in the eyre crate, which seems sufficient to me. After this change there are only two more build warnings for eyre and color-spantrace, the future-incompat dependency warning and the more serious filename collision. <quote> Lint private_interfaces is reported when a type with visibility x is used in primary interface of an item with effective visibility y and x < y. This lint is warn-by-default. Lint private_bounds is reported when a type or trait with visibility x is used in secondary interface of an item with effective visibility y and x < y. This lint is warn-by-default. Lint unnameable_types is reported when effective visibility of a type is larger than module in which it can be named, either directly, or through reexports, or through trivial type aliases (type X = Y;, no generics on both sides). This lint is allow-by-default. Compatibility lint private_in_public is never reported and removed. </quote>
color-spantrace
A rust library for colorizing tracing_error::SpanTrace
objects in the style
of color-backtrace
.
Setup
Add the following to your Cargo.toml
:
[dependencies]
color-spantrace = "0.2"
tracing = "0.1"
tracing-error = "0.2"
tracing-subscriber = "0.3"
Setup a tracing subscriber with an ErrorLayer
:
use tracing_error::ErrorLayer;
use tracing_subscriber::{prelude::*, registry::Registry};
Registry::default().with(ErrorLayer::default()).init();
Create spans and enter them:
use tracing::instrument;
use tracing_error::SpanTrace;
#[instrument]
fn foo() -> SpanTrace {
SpanTrace::capture()
}
And finally colorize the SpanTrace
:
use tracing_error::SpanTrace;
let span_trace = SpanTrace::capture();
println!("{}", color_spantrace::colorize(&span_trace));
Example
This example is taken from examples/color-spantrace-usage.rs
:
use tracing::instrument;
use tracing_error::{ErrorLayer, SpanTrace};
use tracing_subscriber::{prelude::*, registry::Registry};
#[instrument]
fn main() {
Registry::default().with(ErrorLayer::default()).init();
let span_trace = one(42);
println!("{}", color_spantrace::colorize(&span_trace));
}
#[instrument]
fn one(i: u32) -> SpanTrace {
two()
}
#[instrument]
fn two() -> SpanTrace {
SpanTrace::capture()
}
This creates the following output
Minimal Format
Full Format
License
Licensed under either of Apache License, Version 2.0 or MIT license at your option.Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in this crate by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.