sdroege / rtsp-server

RTSP Server Library
Mozilla Public License 2.0
14 stars 2 forks source link

Can't implement client::Client while proxying to basic_client::Client #30

Open nirbheek opened 3 years ago

nirbheek commented 3 years ago

I tried to implement handle_request on the client::Client like this:

use std::pin::Pin;
use futures::prelude::*;

#[derive(Debug)]
pub struct Client {
    basic_client: rtsp_server::client::basic_client::Client,
}

impl Default for Client {
    fn default() -> Self {
        Client {
            basic_client: rtsp_server::client::basic_client::Client::default(),
         }
    }
}

impl rtsp_server::client::Client for Client {
    fn handle_request(
        &mut self,
        ctx: &mut rtsp_server::client::Context<Self>,
        request: rtsp_server::client::OriginalRequest,
    ) -> Pin<
    Box<
            dyn Future<
                Output = Result<
                    rtsp_types::Response<rtsp_server::body::Body>,
                    rtsp_server::error::Error
                >
            > + Send
        >
    > {
        self.basic_client.handle_request(ctx, request)
    }
}

But this fails with:

error[E0308]: mismatched types
  --> src/client/mod.rs:32:42
   |
32 |         self.basic_client.handle_request(ctx, request)
   |                                          ^^^ expected struct `rtsp_server::client::basic_client::Client`, found struct `client::Client`
   |
   = note: expected mutable reference `&mut rtsp_server::client::Context<rtsp_server::client::basic_client::Client>`
              found mutable reference `&mut rtsp_server::client::Context<client::Client>`

I tried to implement a From trait for the clients, but that didn't work either. The workaround is to simply copy basic_client and change whatever you need to.