min-specialization

Crates.iomin-specialization
lib.rsmin-specialization
version0.1.2
sourcesrc
created_at2024-09-01 08:34:19.011764
updated_at2024-09-21 05:54:04.900288
descriptionExperimental implementation of specialization
homepage
repositoryhttps://github.com/yasuo-ozu/min_specialization
max_upload_size
id1359425
size59,570
yozu (yasuo-ozu)

documentation

README

min-specialization Latest Version Documentation GitHub Actions

Rust's specialization feature allows you to provide a default implementation of a trait for generic types and then specialize it for specific types. This feature is currently unstable and only available on the nightly version of Rust.

This crate emulates Rust's #[feature(min_specialization)] unstable feature on stable Rust.

Example

# use min_specialization::specialization;
#[specialization]
mod inner {
    #[allow(unused)]
    trait Trait<U> {
        type Ty;
        fn number(_: U) -> Self::Ty;
    }

    impl<T, U> Trait<U> for T {
        type Ty = usize;
        default fn number(_: U) -> Self::Ty {
            0
        }
    }

    impl<U> Trait<U> for () {
        fn number(_: U) -> Self::Ty {
            1
        }
    }
}

see tests for more.

Commit count: 14

cargo fmt