"expected type parameter, found struct", what I did was wrong here?

pub struct Handler {


pub struct Client {


impl Handler {
    pub fn new() -> Handler {

impl Service for Handler {
    fn client<C: ServiceClient>(&self) -> C {
                                          - expected `C` because of return type
        ^^^^^^^^ expected type parameter, found struct `infrastructure::server::handler::Client`

impl ServiceClient for Client {
    fn read(&mut self, reader: &Read) -> StdIoResult<usize> {

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;

The caller of client gets to choose which type C is, not the implementation. You can use an associated type:

trait Service {
    type Client: ServiceClient;

    fn client(&self) -> Self::Client;

Ok, problem seems to be resolved. Thank you very much :grinning:

Now, I have to get some sleep that I should be getting 8 hours ago.