8
submitted 1 year ago* (last edited 1 year ago) by calcopiritus@lemmy.world to c/rust@lemmy.ml

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

you are viewing a single comment's thread
view the rest of the comments
[-] calcopiritus@lemmy.world 3 points 1 year ago

Yeah, that seems like it would work! Unfortunately I can't use unstable features. I'll keep it in mind for other projects though.

this post was submitted on 10 Sep 2023
8 points (100.0% liked)

Rust Programming

8093 readers
1 users here now

founded 5 years ago
MODERATORS