stratus/infra/tracing/tracing_entered_wrap.rs
1use std::marker::PhantomData;
2
3use tracing::span::Entered;
4
5/// A wrapper around `tracing::span::Entered` that is not `Send`.
6///
7/// This is useful for ensuring that a span is not sent to another thread,
8/// specially to prevent most cases of spans being helf accross await points.
9pub struct EnteredWrap<'a> {
10 // we only care about its destructor
11 _entered: Entered<'a>,
12 _not_send: NotSendMarker,
13}
14
15impl<'a> EnteredWrap<'a> {
16 pub fn new(entered: Entered<'a>) -> Self {
17 Self {
18 _entered: entered,
19 _not_send: PhantomData,
20 }
21 }
22}
23
24// workaround for making a type !Send while negative trait bounds is an unstable feature
25type NotSendMarker = PhantomData<*mut ()>;