mirror of
https://github.com/tokio-rs/tracing.git
synced 2025-10-02 07:20:35 +00:00
subscriber: remove Layer
impls for Arc
s (#1649)
Implementing `Layer` for `Arc`s, which are immutable, breaks the ability to implement `Layer::on_layer` with a mutable reference. This is necessary for per-layer filtering. See https://github.com/tokio-rs/tracing/pull/1576#discussion_r711609810 for details. Therefore, the `Layer` impls for `Arc`s should not be used. In 0.3, we have the opportunity to remove these APIs. Therefore, this PR removes them.
This commit is contained in:
parent
c8b91caa05
commit
b420ae7f4c
@ -1175,6 +1175,11 @@ where
|
||||
|
||||
macro_rules! layer_impl_body {
|
||||
() => {
|
||||
#[inline]
|
||||
fn on_layer(&mut self, subscriber: &mut S) {
|
||||
self.deref_mut().on_layer(subscriber);
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn new_span(&self, attrs: &span::Attributes<'_>, id: &span::Id, ctx: Context<'_, S>) {
|
||||
self.deref().new_span(attrs, id, ctx)
|
||||
@ -1238,48 +1243,11 @@ macro_rules! layer_impl_body {
|
||||
};
|
||||
}
|
||||
|
||||
impl<L, S> Layer<S> for Arc<L>
|
||||
where
|
||||
L: Layer<S>,
|
||||
S: Subscriber,
|
||||
{
|
||||
fn on_layer(&mut self, subscriber: &mut S) {
|
||||
if let Some(inner) = Arc::get_mut(self) {
|
||||
// XXX(eliza): this may behave weird if another `Arc` clone of this
|
||||
// layer is layered onto a _different_ subscriber...but there's no
|
||||
// good solution for that...
|
||||
inner.on_layer(subscriber);
|
||||
}
|
||||
}
|
||||
|
||||
layer_impl_body! {}
|
||||
}
|
||||
|
||||
impl<S> Layer<S> for Arc<dyn Layer<S> + Send + Sync>
|
||||
where
|
||||
S: Subscriber,
|
||||
{
|
||||
fn on_layer(&mut self, subscriber: &mut S) {
|
||||
if let Some(inner) = Arc::get_mut(self) {
|
||||
// XXX(eliza): this may behave weird if another `Arc` clone of this
|
||||
// layer is layered onto a _different_ subscriber...but there's no
|
||||
// good solution for that...
|
||||
inner.on_layer(subscriber);
|
||||
}
|
||||
}
|
||||
|
||||
layer_impl_body! {}
|
||||
}
|
||||
|
||||
impl<L, S> Layer<S> for Box<L>
|
||||
where
|
||||
L: Layer<S>,
|
||||
S: Subscriber,
|
||||
{
|
||||
fn on_layer(&mut self, subscriber: &mut S) {
|
||||
self.deref_mut().on_layer(subscriber);
|
||||
}
|
||||
|
||||
layer_impl_body! {}
|
||||
}
|
||||
|
||||
@ -1287,10 +1255,6 @@ impl<S> Layer<S> for Box<dyn Layer<S> + Send + Sync>
|
||||
where
|
||||
S: Subscriber,
|
||||
{
|
||||
fn on_layer(&mut self, subscriber: &mut S) {
|
||||
self.deref_mut().on_layer(subscriber);
|
||||
}
|
||||
|
||||
layer_impl_body! {}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user