Suppose I have something with generics and a trait with associated types like this:
pub struct MyAwesumType<A, B> {
_value_of_type_a: A,
_value_of_type_b: B,
}
pub trait MyTrait {
type SomeDescriptionOfWhatAIsFor;
type SomeDescriptionOfWhatBIsFor;
type Error;
fn get_the_thing(
&self,
) -> std::result::Result<
MyAwesumType<Self::SomeDescriptionOfWhatAIsFor, Self::SomeDescriptionOfWhatBIsFor>,
Self::Error,
>;
}
What I want to do is alias the "specialization" in that return type to make it less burdensome to read when grokking the trait. For example I'd like to do this, which is not valid:
pub struct MyAwesumType<A, B> {
_value_of_type_a: A,
_value_of_type_b: B,
}
pub trait MyTrait {
type SomeDescriptionOfWhatAIsFor;
type SomeDescriptionOfWhatBIsFor;
type Error;
use MyAwesumType as MyAwesumType<Self::SomeDescriptionOfWhatAIsFor, Self::SomeDescriptionOfWhatBIsFor>;
use Result<T> as std::result::Result<T, Self::Error>
fn get_the_thing(&self) -> Result<MyAwesumType>;
}
fn main() {
println!("Hello, world!");
}
Or maybe like this, also invalid:
pub struct MyAwesumType<A, B> {
_value_of_type_a: A,
_value_of_type_b: B,
}
pub trait MyTrait {
type SomeDescriptionOfWhatAIsFor;
type SomeDescriptionOfWhatBIsFor;
type Error;
type MyAwesumType =
MyAwesumType<Self::SomeDescriptionOfWhatAIsFor, Self::SomeDescriptionOfWhatBIsFor>;
type Result<T> = std::result::Result<T, Self::Error>;
fn get_the_thing(&self) -> Self::Result<Self::MyAwesumType>;
}
Is there any way to do some, if not all, of the type aliasing that I would like to do in the trait definition?