Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save tstellanova/72fb94d5298308af2ef365a3e50cae5f to your computer and use it in GitHub Desktop.
Save tstellanova/72fb94d5298308af2ef365a3e50cae5f to your computer and use it in GitHub Desktop.
Align the associated error types of multiple traits (when you know they're actually the same type)
trait T {
type TErr;
}
trait U {
type UErr;
}
#[derive(Debug)]
struct S;
impl T for S {
type TErr = &'static str;
}
impl U for S {
type UErr = &'static str;
}
fn setup() -> (
impl T<TErr = &'static str> + U<UErr = &'static str> + std::fmt::Debug,
u32,
) {
(S, 5)
}
fn main() {
let (s, _) = setup();
dbg!(s);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment