diff --git a/async-std/src/runtime.rs b/async-std/src/runtime.rs index b5872ea135..8185b64b44 100644 --- a/async-std/src/runtime.rs +++ b/async-std/src/runtime.rs @@ -1,5 +1,5 @@ use futures_lite::future::FutureExt; -use std::{future::Future, time::Duration}; +use std::{future::Future, sync::Arc, time::Duration}; use trillium_server_common::{DroppableFuture, Runtime, RuntimeTrait, Stream}; /// async-std runtime @@ -89,6 +89,6 @@ impl AsyncStdRuntime { impl From for Runtime { fn from(value: AsyncStdRuntime) -> Self { - Runtime::from_trait_impl(value) + Arc::new(value).into() } } diff --git a/server-common/src/runtime.rs b/server-common/src/runtime.rs index 2a609162b2..8ba52e9046 100644 --- a/server-common/src/runtime.rs +++ b/server-common/src/runtime.rs @@ -26,19 +26,18 @@ impl Debug for Runtime { } } +impl From> for Runtime { + fn from(value: Arc) -> Self { + Self(value) + } +} + impl Runtime { /// Construct a new type-erased runtime object from any [`RuntimeTrait`] implementation. pub fn new(runtime: impl RuntimeTrait) -> Self { runtime.into() // we avoid re-arcing a Runtime by using Into::into } - // in order to avoid re-arcing Runtime in new / into, we use this to actually construct the - // Runtime within From implementations on the runtime trait type - #[doc(hidden)] - pub fn from_trait_impl(runtime: impl RuntimeTrait) -> Self { - Self(Arc::new(runtime)) - } - /// Spawn a future on the runtime, returning a future that has detach-on-drop semantics /// /// Spawned tasks conform to the following behavior: diff --git a/smol/src/runtime.rs b/smol/src/runtime.rs index 20d26f0bf1..7aceceddb9 100644 --- a/smol/src/runtime.rs +++ b/smol/src/runtime.rs @@ -4,6 +4,7 @@ use futures_lite::{FutureExt, Stream, StreamExt}; use std::{ future::Future, pin::Pin, + sync::Arc, task::{Context, Poll}, time::Duration, }; @@ -113,6 +114,6 @@ impl SmolRuntime { impl From for Runtime { fn from(value: SmolRuntime) -> Self { - Runtime::from_trait_impl(value) + Arc::new(value).into() } } diff --git a/testing/src/runtimeless/runtime.rs b/testing/src/runtimeless/runtime.rs index 76643a2e63..b96c740151 100644 --- a/testing/src/runtimeless/runtime.rs +++ b/testing/src/runtimeless/runtime.rs @@ -1,5 +1,5 @@ use futures_lite::{future, Stream}; -use std::{future::Future, thread, time::Duration}; +use std::{future::Future, sync::Arc, thread, time::Duration}; use trillium_server_common::{DroppableFuture, Runtime, RuntimeTrait}; /// a runtime that isn't a runtime @@ -49,11 +49,13 @@ impl RuntimeTrait for RuntimelessRuntime { future::block_on(fut) } } + impl From for Runtime { fn from(value: RuntimelessRuntime) -> Self { - Runtime::from_trait_impl(value) + Arc::new(value).into() } } + impl RuntimelessRuntime { /// Spawn a future on the runtime, returning a future that has detach-on-drop semantics /// diff --git a/tokio/src/runtime.rs b/tokio/src/runtime.rs index 6e21cd2264..c2a7a381ec 100644 --- a/tokio/src/runtime.rs +++ b/tokio/src/runtime.rs @@ -120,6 +120,6 @@ impl TokioRuntime { impl From for Runtime { fn from(value: TokioRuntime) -> Self { - Runtime::from_trait_impl(value) + Arc::new(value).into() } }