#traits #async-trait #impl #async

macro no-std trait-make

Utilities for working with impl traits in Rust

1 unstable release

0.1.0 Feb 17, 2024

#28 in #trait

Download history 417/week @ 2024-11-15 263/week @ 2024-11-22 486/week @ 2024-11-29 431/week @ 2024-12-06 548/week @ 2024-12-13 506/week @ 2024-12-20 598/week @ 2024-12-27 637/week @ 2025-01-03 516/week @ 2025-01-10 378/week @ 2025-01-17 267/week @ 2025-01-24 424/week @ 2025-01-31 530/week @ 2025-02-07 595/week @ 2025-02-14 880/week @ 2025-02-21 721/week @ 2025-02-28

2,804 downloads per month
Used in 7 crates (via fuse3)

MIT/Apache

15KB
239 lines

Latest Version Documentation GHA Status License

fork from https://github.com/rust-lang/impl-trait-utils

trait_variant is a good lib, but it still doesn't support default method, so fork it and create a new lib trait-make to support default method

users can replace trait_variant with a few change

trait_make

trait_make generates a specialized version of a base trait that uses async fn and/or -> impl Trait.

For example, if you want a Sendable version of your trait, you'd write:

#[trait_make::make(IntFactory: Send)]
trait LocalIntFactory {
    async fn make(&self) -> i32;
    fn stream(&self) -> impl Iterator<Item = i32>;
    fn call(&self) -> u32;
}

The trait_make::make would generate an additional trait called IntFactory:

use core::future::Future;

trait IntFactory: Send {
   fn make(&self) -> impl Future<Output = i32> + Send;
   fn stream(&self) -> impl Iterator<Item = i32> + Send;
   fn call(&self) -> u32;
}

Implementers can choose to implement either LocalIntFactory or IntFactory as appropriate.

For more details, see the docs for trait_make::make.

License and usage notes

Licensed under either of Apache License, Version 2.0 or MIT license at your option.

Dependencies

~200–640KB
~15K SLoC