erased-generic-trait

Crates.ioerased-generic-trait
lib.rserased-generic-trait
version0.0.4
sourcesrc
created_at2023-10-31 12:27:17.412264
updated_at2023-11-11 12:08:30.869887
descriptionMacros for generating trait objects from traits with generic methods
homepage
repositoryhttps://github.com/ecoricemon/erased-generic-trait
max_upload_size
id1019780
size71,970
ecoricemon (ecoricemon)

documentation

README

erased-generic-trait

A Rust crate for generating trait objects from traits with generic methods.

When to use

  • When you want to make a trait obejct from a trait having generic methods.
  • When generic methods have only one kind of bounds.
  • When generic methods require 'static lifetime.
  • When you can know all types that are passed to generic methods before converting into a trait object.

Motivation

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 TypeIds 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 TypeIds. But you should know this approach is not efficient.


Please read rust documentation of this crate for more details.

Commit count: 5

cargo fmt