Problems when implements trait for trait

⚓ Rust    📅 2025-07-01    👤 surdeus    👁️ 3      

surdeus

Warning

This post was published 37 days ago. The information described in this article may have changed.

String : !Copy, but if I impl<F: Copy> X for F, then I can't impl X for String, because

upstream crates may add a new impl of trait std::marker::Copy for type std::string::String in future versions

That is ridiculous, if that will happen in the future, refuses the code at that time, why refuses it now.

How can I get through this

trait X {
    fn callx(&self);
}

impl<F: Copy> X for F {
    fn callx(&self) {
        println!("Copy");
    }
}

impl X for String {
    fn callx(&self) {
        println!("String");
    }
}

fn main() {} 

2 posts - 2 participants

Read full topic

🏷️ rust_feed