pub struct Handler {
}
pub struct Client {
}
impl Handler {
pub fn new() -> Handler {
Handler{}
}
}
impl Service for Handler {
fn client<C: ServiceClient>(&self) -> C {
- expected `C` because of return type
Client{}
^^^^^^^^ expected type parameter, found struct `infrastructure::server::handler::Client`
}
}
impl ServiceClient for Client {
fn read(&mut self, reader: &Read) -> StdIoResult<usize> {
Ok(0)
}
}
In Service
, method client
creates a Client
which implements ServiceClient
. But this cause Rust refuse to compile.
What's wrong with my code?
Here is the declaration of those two traits:
pub trait ServiceClient {
fn read(&mut self, reader: &Read) -> StdIoResult<usize>;
}
pub trait Service {
fn client<C: Client>(&self) -> C;
}