Skip to content

Commit 95670ce

Browse files
authored
Context: Rc -> Arc (#127)
1 parent c823385 commit 95670ce

File tree

3 files changed

+12
-12
lines changed

3 files changed

+12
-12
lines changed

src/api/context/mod.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ use std::cell::RefCell;
6868
use std::collections::HashMap;
6969
use std::fmt;
7070
use std::hash::{BuildHasherDefault, Hasher};
71-
use std::rc::Rc;
71+
use std::sync::Arc;
7272

7373
pub mod propagation;
7474

@@ -80,7 +80,7 @@ thread_local! {
8080
/// An execution-scoped collection of values.
8181
#[derive(Clone, Default)]
8282
pub struct Context {
83-
entries: HashMap<TypeId, Rc<dyn Any>, BuildHasherDefault<IdHasher>>,
83+
entries: HashMap<TypeId, Arc<dyn Any + Sync + Send>, BuildHasherDefault<IdHasher>>,
8484
}
8585

8686
impl Context {
@@ -141,11 +141,11 @@ impl Context {
141141
/// assert_eq!(all_current_and_b.get::<ValueA>(), Some(&ValueA("a")));
142142
/// assert_eq!(all_current_and_b.get::<ValueB>(), Some(&ValueB(42)));
143143
/// ```
144-
pub fn current_with_value<T: 'static>(value: T) -> Self {
144+
pub fn current_with_value<T: 'static + Send + Sync>(value: T) -> Self {
145145
let mut new_context = Context::current();
146146
new_context
147147
.entries
148-
.insert(TypeId::of::<T>(), Rc::new(value));
148+
.insert(TypeId::of::<T>(), Arc::new(value));
149149

150150
new_context
151151
}
@@ -204,11 +204,11 @@ impl Context {
204204
/// assert_eq!(cx_with_a_and_b.get::<ValueA>(), Some(&ValueA("a")));
205205
/// assert_eq!(cx_with_a_and_b.get::<ValueB>(), Some(&ValueB(42)));
206206
/// ```
207-
pub fn with_value<T: 'static>(&self, value: T) -> Self {
207+
pub fn with_value<T: 'static + Send + Sync>(&self, value: T) -> Self {
208208
let mut new_context = self.clone();
209209
new_context
210210
.entries
211-
.insert(TypeId::of::<T>(), Rc::new(value));
211+
.insert(TypeId::of::<T>(), Arc::new(value));
212212

213213
new_context
214214
}

src/api/trace/context.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,20 @@ lazy_static::lazy_static! {
55
static ref NOOP_SPAN: api::NoopSpan = api::NoopSpan::new();
66
}
77

8-
struct Span(Box<dyn api::Span>);
8+
struct Span(Box<dyn api::Span + Send + Sync>);
99
struct RemoteSpanContext(api::SpanContext);
1010

1111
/// Methods for storing and retrieving trace data in a context.
1212
pub trait TraceContextExt {
1313
/// Returns a clone of the current context with the included span.
1414
///
1515
/// This is useful for building tracers.
16-
fn current_with_span<T: api::Span>(span: T) -> Self;
16+
fn current_with_span<T: api::Span + Send + Sync>(span: T) -> Self;
1717

1818
/// Returns a clone of this context with the included span.
1919
///
2020
/// This is useful for building tracers.
21-
fn with_span<T: api::Span>(&self, span: T) -> Self;
21+
fn with_span<T: api::Span + Send + Sync>(&self, span: T) -> Self;
2222

2323
/// Returns a reference to this context's span, or the default no-op span if
2424
/// none has been set.
@@ -51,11 +51,11 @@ pub trait TraceContextExt {
5151
}
5252

5353
impl TraceContextExt for api::Context {
54-
fn current_with_span<T: api::Span>(span: T) -> Self {
54+
fn current_with_span<T: api::Span + Send + Sync>(span: T) -> Self {
5555
api::Context::current_with_value(Span(Box::new(span)))
5656
}
5757

58-
fn with_span<T: api::Span>(&self, span: T) -> Self {
58+
fn with_span<T: api::Span + Send + Sync>(&self, span: T) -> Self {
5959
self.with_value(Span(Box::new(span)))
6060
}
6161

src/api/trace/span.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use std::fmt;
2222
use std::time::SystemTime;
2323

2424
/// Interface for a single operation within a trace.
25-
pub trait Span: fmt::Debug + 'static {
25+
pub trait Span: fmt::Debug + 'static + Send + Sync {
2626
/// An API to record events in the context of a given `Span`.
2727
///
2828
/// Events have a time associated with the moment when they are

0 commit comments

Comments
 (0)