There are a dozen complex trait bounds which are frequently used. I don't want to write them again and again, how to make an alias of these bounds?
type MapOutput<'a, T> = <T as MapVisit<ApplyGlobalContent<'a>>>::Output;
fn foo<T>()
where
T: for<'a> MapVisit<ApplyGlobalContent<'a>>,
for<'a> MapOutput<'a, T>: SpecificUpdate,
for<'a> <MapOutput<'a, T> as SpecificUpdate>::UpdateTo:
RenderObject + UpdateWith<MapOutput<'a, T>> + 'static,
{
}
I tried to put them into a trait, but failed.
pub trait ChildrenNodes
where
// lots of trait bounds
{
}
type MapOutput<'a, T> = <T as MapVisit<ApplyGlobalContent<'a>>>::Output;
impl<T> ChildrenNodes for T
where
// lots of trait bounds
{
}
// doesn't compile
fn foo<T>()
where
T: ChildrenNodes
{
}
rustc still requires me to complete the trait bounds.
error[E0277]: the trait bound `for<'a> <T as MapVisit<ApplyGlobalContent<'a>>>::Output: SpecificUpdate` is not satisfied
--> irisia-core\src\dom\children\set_children.rs:34:8
|
34 | T: ChildrenNodes,
| ^^^^^^^^^^^^^ the trait `for<'a> SpecificUpdate` is not implemented for `<T as MapVisit<ApplyGlobalContent<'a>>>::Output`
|
= help: the following other types implement trait `SpecificUpdate`:
()
ElModelUpdate<'_, El, Pr, Sty, Ch, Oc, Sr>
once::Once<T>
repeating::Repeat<I>
structure::branch::Branch<A, B>
structure::chain::Chain<A, B>
note: required by a bound in `ChildrenNodes`
--> irisia-core\src\dom\children\set_children.rs:15:34
|
12 | pub trait ChildrenNodes
| ------------- required by a bound in this trait
...
15 | for<'a> MapOutput<'a, Self>: SpecificUpdate,
| ^^^^^^^^^^^^^^ required by this bound in `ChildrenNodes`
I tried macros, but failed too. Macro calls are only allowed at type position.
fn foo<T>()
where
alias!(T), // doesn't compile, syntax error
{}
Thank anybody for your help.