trait-variant

Crates.iotrait-variant
lib.rstrait-variant
version0.1.2
sourcesrc
created_at2023-12-15 00:47:44.920635
updated_at2024-03-18 22:43:08.58141
descriptionUtilities for working with impl traits in Rust
homepage
repositoryhttps://github.com/rust-lang/impl-trait-utils
max_upload_size
id1070540
size19,536
(rust-lang-owner)

documentation

README

Latest Version Documentation GHA Status License

Utilities for working with impl Traits in Rust.

trait_variant

trait_variant 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_variant::make(IntFactory: Send)]
trait LocalIntFactory {
    async fn make(&self) -> i32;
    fn stream(&self) -> impl Iterator<Item = i32>;
    fn call(&self) -> u32;
}

The trait_variant::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_variant::make.

License and usage notes

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

Commit count: 68

cargo fmt