Crates.io | erased-generic-trait |
lib.rs | erased-generic-trait |
version | 0.0.4 |
source | src |
created_at | 2023-10-31 12:27:17.412264 |
updated_at | 2023-11-11 12:08:30.869887 |
description | Macros for generating trait objects from traits with generic methods |
homepage | |
repository | https://github.com/ecoricemon/erased-generic-trait |
max_upload_size | |
id | 1019780 |
size | 71,970 |
A Rust crate for generating trait objects from traits with generic methods.
In Rust, only object safe traits can become trait objects, generic methods make them not object safe.
To overcome this limitation, we can use dyn Any
as parameters to take generic arguments
from non-generic methods, and call the generic methods in them.
We can inspect TypeId
s from the 'dyn Ayn's, but we can't know concrete types from the 'TypeId's.
So macros are going to inject functions calling generic methods with the concrete types,
and invoke those functions according to the TypeId
s.
But you should know this approach is not efficient.
Please read rust documentation of this crate for more details.