I am working on a actor project which need alias for the trait because it is so long, but even with the nightly feature #![feature(trait_alias)] seems can not achieve.
In short I write a playground:
I want alias A<T> to be shorter causing I have many generic type on A in real case; and the same time I want to access the type Output = Self; from its implementations B.
Appreciate for any help.
https://play.rust-lang.org/?version=nightly&mode=debug&edition=2018&gist=5a9bb8d3f76112c0b73ea1da8af34959
#![feature(trait_alias)]
trait A<T> {
type Output;
fn test(a: T) -> Self::Output;
}
//To alias the trait, real situation longer than this.
//attempt 1:
trait B: A<String>{}
//attempt 2:
//trait B : A<String, Output=Self> where Self: std::marker::Sized {}
//impl<T> B for T where T: A<String, Output=T> {}
//attempt 3 with trait_alias:
//trait B = A<String>;
struct SA;
impl B for SA {
type Output = Self;
}
trait alias is only mean to be:
used wherever traits would normally be used as either bounds or trait objects. Source
So, your use case doesn't match, you can't do that.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With