mirror of
https://github.com/tokio-rs/tokio.git
synced 2026-08-29 00:00:11 +02:00
trace-core: API polish (#962)
This branch makes a handful of `tokio-trace-core` API improvements, mostly around naming. In particular: * Rename `dispatcher::with` to `dispatcher::get_default` * Rename `Event::observe` to `Event::dispatch` * Make `field::ValidLen` trait private Closes #948 Closes #960 Signed-off-by: Eliza Weisman <[email protected]>
This commit is contained in:
@@ -52,11 +52,10 @@ pub fn with_default<T>(dispatcher: Dispatch, f: impl FnOnce() -> T) -> T {
|
||||
let _guard = ResetGuard(prior.ok());
|
||||
f()
|
||||
}
|
||||
|
||||
/// Executes a closure with a reference to this thread's current [dispatcher].
|
||||
///
|
||||
/// [dispatcher]: ../dispatcher/struct.Dispatch.html
|
||||
pub fn with<T, F>(mut f: F) -> T
|
||||
pub fn get_default<T, F>(mut f: F) -> T
|
||||
where
|
||||
F: FnMut(&Dispatch) -> T,
|
||||
{
|
||||
|
||||
@@ -27,9 +27,9 @@ impl<'a> Event<'a> {
|
||||
/// Constructs a new `Event` with the specified metadata and set of values,
|
||||
/// and observes it with the current subscriber.
|
||||
#[inline]
|
||||
pub fn observe(metadata: &'a Metadata<'a>, fields: &'a field::ValueSet) {
|
||||
pub fn dispatch(metadata: &'a Metadata<'a>, fields: &'a field::ValueSet) {
|
||||
let event = Event { metadata, fields };
|
||||
::dispatcher::with(|current| {
|
||||
::dispatcher::get_default(|current| {
|
||||
current.event(&event);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -45,6 +45,8 @@ use std::{
|
||||
ops::Range,
|
||||
};
|
||||
|
||||
use self::private::ValidLen;
|
||||
|
||||
/// An opaque key allowing _O_(1) access to a field in a `Span`'s key-value
|
||||
/// data.
|
||||
///
|
||||
@@ -227,15 +229,6 @@ pub struct DisplayValue<T: fmt::Display>(T);
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct DebugValue<T: fmt::Debug>(T);
|
||||
|
||||
/// Marker trait implemented by arrays which are of valid length to
|
||||
/// construct a `ValueSet`.
|
||||
///
|
||||
/// `ValueSet`s may only be constructed from arrays containing 32 or fewer
|
||||
/// elements, to ensure the array is small enough to always be allocated on the
|
||||
/// stack. This trait is only implemented by arrays of an appropriate length,
|
||||
/// ensuring that the correct size arrays are used at compile-time.
|
||||
pub trait ValidLen<'a>: ::sealed::Sealed + Borrow<[(&'a Field, Option<&'a (Value + 'a)>)]> {}
|
||||
|
||||
/// Wraps a type implementing `fmt::Display` as a `Value` that can be
|
||||
/// recorded using its `Display` implementation.
|
||||
pub fn display<T>(t: T) -> DisplayValue<T>
|
||||
@@ -615,12 +608,23 @@ impl<'a> fmt::Debug for ValueSet<'a> {
|
||||
|
||||
// ===== impl ValidLen =====
|
||||
|
||||
mod private {
|
||||
use super::*;
|
||||
|
||||
/// Marker trait implemented by arrays which are of valid length to
|
||||
/// construct a `ValueSet`.
|
||||
///
|
||||
/// `ValueSet`s may only be constructed from arrays containing 32 or fewer
|
||||
/// elements, to ensure the array is small enough to always be allocated on the
|
||||
/// stack. This trait is only implemented by arrays of an appropriate length,
|
||||
/// ensuring that the correct size arrays are used at compile-time.
|
||||
pub trait ValidLen<'a>: Borrow<[(&'a Field, Option<&'a (Value + 'a)>)]> {}
|
||||
}
|
||||
|
||||
macro_rules! impl_valid_len {
|
||||
( $( $len:tt ),+ ) => {
|
||||
$(
|
||||
impl<'a> ::sealed::Sealed for
|
||||
[(&'a Field, Option<&'a (Value + 'a)>); $len] {}
|
||||
impl<'a> ValidLen<'a> for
|
||||
impl<'a> private::ValidLen<'a> for
|
||||
[(&'a Field, Option<&'a (Value + 'a)>); $len] {}
|
||||
)+
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user