我开始使用ws,希望将Handler特性的实现拆分为多个文件。因此,我在一个名为
在另一个文件中,
在编译时,我遇到了以下错误:
我希望文件能够分开,这样每个开发人员都可以单独处理一个文件。是否有办法实现这一点,或者我必须在单个文件中拥有完整的特性实现?
on_open.rs
的文件中编写了以下内容:impl Handler for Client {
fn on_open(&mut self, _: Handshake) -> Result<()> {
println!("Socket opened");
Ok(())
}
}
在另一个文件中,
on_message.rs
:impl Handler for Client {
fn on_message(&mut self, msg: Message) -> Result<()> {
println!("Server got message '{}'. ", msg);
Ok(())
}
}
在编译时,我遇到了以下错误:
error[E0119]: conflicting implementations of trait `ws::handler::Handler` for type `models::client::Client`:
--> src\sockets\on_message.rs:9:1
|
9 | impl Handler for Client {
| ^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `models::client::Client`
|
::: src\sockets\on_open.rs:8:1
|
8 | impl Handler for Client {
| ----------------------- first implementation here
我希望文件能够分开,这样每个开发人员都可以单独处理一个文件。是否有办法实现这一点,或者我必须在单个文件中拥有完整的特性实现?