Implement trait for external structures use a statement block

Sometime, we want to Implement some method with other mod struct, it need write two statement block:

mod block1{
    pub structA;
}

mod block2{
    use super::block1::structA;
    trait MyTrait {
       fn foo(self);
    }

    impl MyTrait for structA {
        fn foo(self){
            println!("this is foo method");
        }
    }
}

I think it can be integrated into this way:

mod block1{
    pub structA;
}

mod block2{
    use super::block1::structA;

    trait MyTrait for structA {
        fn foo(self){
            println!("this is foo method");
        }
    }

    pub trait MyTrait2 for structA {
        fn foo2(self){
            println!("this is foo method");
        }
    }
}

Is there any problem in doing this?

This is not valid Rust syntax.
What are you trying to achieve here?

Yes, the current rust does not support it. Maybe it is a feature worth implementing

This might be better suited for IRLO, since that's essentially a change of syntax. You're proposing to merge extension trait definition with its implementation, if I understand correctly?

Thanks , I thought I had no right to speak in IRLO,

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.