generic_trait_alias

Crates.iogeneric_trait_alias
lib.rsgeneric_trait_alias
version0.1.2
sourcesrc
created_at2023-07-26 14:19:56.06499
updated_at2023-07-26 22:53:02.919943
descriptionA proc-macro attribute which can be used to create custom type aliases for abstraction
homepage
repositoryhttps://github.com/vidur2/generic_trait_alias
max_upload_size
id926496
size11,030
Vidur (vidur2)

documentation

README

generic_trait_alias

Holds a proc_macro_attribute which can be used to create type aliases with a more inutive syntax (similar to the way struct aliases are handled)

Install

cargo install generic_trait_alias

or

cargo add generic_trait_alias

Examples

use generic_trait_alias::trait_alias;

// Define internal trait
pub trait Z {
    fn z(&self) -> u8;
}

// Creates a pub trait alias with internal and external traits
#[trait_alias]
pub type X = Z + Clone;

// Creates a private trait alias with internal and external traits
#[trait_alias]
type A = Z + Clone;

// Only works with public alias x
pub fn example_pub<T: X>(x: T) {
    println!("{}", x.z());
}

// Private functions can work with public or private alias
fn example<T: A>(x: A) {
    println!("{}", x.z());
}

Limitations

Currently does not support combined generic traits

Commit count: 24

cargo fmt