Skip to content

More ergonomic common case of immediately entering the span.  #1246

@matklad

Description

@matklad

When writing non-async code, the common case is that a span precisely corresponds to a lexical scope. At the moment, this case requires an introduction of otherwise unnecessary local variable:

let span = tracing::info_span!("spam");
let _span = span.enter();

I wish the following worked:

let _span = tracing::info_span_enter!("spam");

To do this, I think we can introduce a second version of Entered:

pub struct EnteredScope {
    span: Span, // note: owns the span
    _not_send: PhantomData<*mut ()>,
}

after that, all the lifetimes should work out.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions