| Crates.io | min-specialization |
| lib.rs | min-specialization |
| version | 0.1.2 |
| created_at | 2024-09-01 08:34:19.011764+00 |
| updated_at | 2024-09-21 05:54:04.900288+00 |
| description | Experimental implementation of specialization |
| homepage | |
| repository | https://github.com/yasuo-ozu/min_specialization |
| max_upload_size | |
| id | 1359425 |
| size | 59,570 |
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.
# 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.