pub trait DowncastAnyAsyncEngine {
// Required method
fn downcast<Req, Resp, E>(
&self,
) -> Option<Arc<dyn AsyncEngine<Req, Resp, E>>>
where Req: Data,
Resp: Data + AsyncEngineContextProvider,
E: Data;
}
Expand description
An extension trait that provides a convenient method to downcast an AnyAsyncEngine
.
This trait provides the .downcast<Req, Resp, E>()
method on Arc<dyn AnyAsyncEngine>
,
enabling safe downcasting back to the original typed engine.
§Safety
The downcast method performs runtime type checking using TypeId
comparison.
It will only succeed if the type parameters exactly match the original engine’s types.
§Usage
ⓘ
use crate::engine::DowncastAnyAsyncEngine;
let any_engine: Arc<dyn AnyAsyncEngine> = // ... from collection
if let Some(typed_engine) = any_engine.downcast::<String, String, ()>() {
// Use the typed engine
let result = typed_engine.generate("hello".to_string()).await;
}
Required Methods§
Sourcefn downcast<Req, Resp, E>(&self) -> Option<Arc<dyn AsyncEngine<Req, Resp, E>>>
fn downcast<Req, Resp, E>(&self) -> Option<Arc<dyn AsyncEngine<Req, Resp, E>>>
Attempts to downcast an AnyAsyncEngine
to a specific AsyncEngine
type.
Returns Some(engine)
if the type parameters match the original engine,
or None
if the types don’t match.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.