Skip to content

how can establish() and io() preserve more of lifetime and type for io argument? #178

@mcr

Description

@mcr

I am trying to connect MbedTls to the ureq's newest TLSConnector.
My WIP (does not compile) is at:
https://github.com/AnimaGUS-minerva/ureq/tree/mbedtls-2/examples/mbedtls-req

I pass the desired tcp_stream into establish(), and return a Box that has the dyn ReadWrite trait:

impl TlsConnector for MbedTlsConnector {
    fn connect(
        &self,
        dns_name: &str,
        tcp_stream: TcpStream,
    ) -> Result<Box<dyn ReadWrite>, Error> {

        let ctx = self.context.lock().unwrap();

        match ctx.establish(tcp_stream, None) {

I need to implement a socket routine for this, returning the same tcp_stream as before, but the obvious method of calling context.io() isn't going to work, because it return dyn Any, and I think that I need a dyn ReadWrite.

impl ReadWrite for MbedTlsConnector {
    fn socket(&self) -> Option<&TcpStream> {
        let ctx = self.context.lock().unwrap();
        Some(&(ctx.io() as TcpStream))
    }
}

Looking for advice here. Maybe the wrapper establish()/io() should change?
Or what?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions