pub trait AnyAsyncEngine: Send + Sync {
// Required methods
fn request_type_id(&self) -> TypeId;
fn response_type_id(&self) -> TypeId;
fn error_type_id(&self) -> TypeId;
fn as_any(&self) -> &dyn Any;
}
Expand description
A type-erased AsyncEngine
.
This trait enables storing heterogeneous AsyncEngine
implementations in collections
by erasing their specific generic type parameters. It provides runtime type information
and safe downcasting capabilities.
§Type Erasure Mechanism
The trait uses std::any::TypeId
to preserve type information at runtime, allowing
safe downcasting back to the original AsyncEngine<Req, Resp, E>
types.
§Safety Guarantees
- Type IDs are preserved exactly as they were during type erasure
- Downcasting is only possible to the original type combination
- Incorrect downcasts return
None
rather than panicking
§Implementation Notes
This trait is implemented by the internal AnyEngineWrapper
struct. Users should
not implement this trait directly - use the AsAnyAsyncEngine
extension trait instead.
Required Methods§
Sourcefn request_type_id(&self) -> TypeId
fn request_type_id(&self) -> TypeId
Returns the TypeId
of the request type used by this engine.
Sourcefn response_type_id(&self) -> TypeId
fn response_type_id(&self) -> TypeId
Returns the TypeId
of the response type used by this engine.
Sourcefn error_type_id(&self) -> TypeId
fn error_type_id(&self) -> TypeId
Returns the TypeId
of the error type used by this engine.