Crates.io | trait-make |
lib.rs | trait-make |
version | 0.1.0 |
source | src |
created_at | 2024-02-17 03:57:49.297857 |
updated_at | 2024-02-17 03:57:49.297857 |
description | Utilities for working with impl traits in Rust |
homepage | |
repository | https://github.com/Sherlock-Holo/impl-trait-utils |
max_upload_size | |
id | 1142998 |
size | 21,475 |
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 Send
able 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
.
Licensed under either of Apache License, Version 2.0 or MIT license at your option.