[help] impl block for generic type overriden by specific type
from calcopiritus@lemmy.world to rust@lemmy.ml on 10 Sep 2023 21:01
https://lemmy.world/post/4825824

I want to do basically this:

struct MyStruct < T> {
    data: T
}

impl < T> for MyStruct < T> {
    fn foo() {
        println!("Generic")
    }
}

impl for MyStruct < u32> {
    fn foo() {
        println!("u32")
    }
}

I have tried doing

impl < T: !u32> for MyStruct < T> {
    ...
}

But it doesn’t seem to work. I’ve also tried various things with traits but none of them seem to work. Is this even possible?

EDIT: Fixed formatting

#rust

threaded - newest