Skip to content

Commit 891b5fc

Browse files
authored
rename method for registering with derived root span (#30)
1 parent c3db1a6 commit 891b5fc

3 files changed

Lines changed: 15 additions & 5 deletions

File tree

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ pub use registry::{AnyKey, Config, ConfigBuilder, ConfigBuilderError, Key, Regis
8888
pub use root::TreeRoot;
8989
pub use span::{Span, SpanExt};
9090
#[cfg(feature = "tokio")]
91-
pub use spawn::{spawn, spawn_anonymous, spawn_root};
91+
pub use spawn::{spawn, spawn_anonymous, spawn_derived_root};
9292

9393
#[doc(hidden)]
9494
pub mod __private {

src/registry.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ use weak_table::WeakValueHashMap;
2323

2424
use crate::context::{ContextId, Tree, TreeContext};
2525
use crate::obj_utils::{DynEq, DynHash};
26-
use crate::{Span, TreeRoot};
26+
use crate::{span, Span, TreeRoot};
2727

2828
/// Configuration for an await-tree registry, which affects the behavior of all await-trees in the
2929
/// registry.
@@ -59,6 +59,12 @@ pub trait ToRootSpan {
5959
fn to_root_span(&self) -> Span;
6060
}
6161

62+
impl<T: Display> ToRootSpan for T {
63+
fn to_root_span(&self) -> Span {
64+
span!("{self}")
65+
}
66+
}
67+
6268
/// Key type for anonymous await-trees.
6369
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
6470
struct AnonymousKey(ContextId);
@@ -232,7 +238,7 @@ impl Registry {
232238
///
233239
/// This is a convenience method for `self.register(key, key.to_root_span())`. See
234240
/// [`Registry::register`] for more details.
235-
pub fn register_root(&self, key: impl Key + ToRootSpan) -> TreeRoot {
241+
pub fn register_derived_root(&self, key: impl Key + ToRootSpan) -> TreeRoot {
236242
let root_span = key.to_root_span();
237243
self.register(key, root_span)
238244
}

src/spawn.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,11 @@ impl Registry {
4545
/// The spawned task will be registered in the this registry.
4646
///
4747
/// This is a convenience method for `self.spawn(key, key.to_root_span(), future)`.
48-
pub fn spawn_root<T>(&self, key: impl Key + ToRootSpan, future: T) -> JoinHandle<T::Output>
48+
pub fn spawn_derived_root<T>(
49+
&self,
50+
key: impl Key + ToRootSpan,
51+
future: T,
52+
) -> JoinHandle<T::Output>
4953
where
5054
T: Future + Send + 'static,
5155
T::Output: Send + 'static,
@@ -94,7 +98,7 @@ where
9498
///
9599
/// This is a convenience function for `spawn(key, key.to_root_span(), future)`. See [`spawn`] for
96100
/// more details.
97-
pub fn spawn_root<T>(key: impl Key + ToRootSpan, future: T) -> JoinHandle<T::Output>
101+
pub fn spawn_derived_root<T>(key: impl Key + ToRootSpan, future: T) -> JoinHandle<T::Output>
98102
where
99103
T: Future + Send + 'static,
100104
T::Output: Send + 'static,

0 commit comments

Comments
 (0)