#How to write less where clauses + lifetimes ?
8 messages · Page 1 of 1 (latest)
the fact that this doesn't work automatically is issue https://github.com/rust-lang/rust/issues/20671
however, it will be simpler if you do the + only in the impls of the trait, not in a default method
in that case, every fn etc that is just calling ImportantTrait doesn't need the additional bounds
?play
use std::fmt::{Debug, Display};
pub trait ImportantTrait<S>: Sized + Clone + Copy + Debug + Default + Display {
fn example(&self, other: &S) -> Self;
}
impl ImportantTrait<i32> for i32 {
fn example(&self, other: &i32) -> Self {
self + other
}
}
pub trait SomeTrait<S, T: ImportantTrait<S>> {}
fn a<S, T: ImportantTrait<S>>(s: &S, t: &T) {
dbg!(t.example(s));
}
pub fn main() {}