Skip to main content

ClientLayer

Trait ClientLayer 

Source
pub trait ClientLayer<In, Out>:
    Send
    + Sync
    + Clone {
    // Required method
    fn handshake(&self, input: In) -> impl Future<Output = Result<Out>> + Send;
}
Expand description

Client-side middleware layer. Upgrades an input via handshake.

Generic over input and output types:

  • ClientLayer<Box<dyn ByteStream>, Box<dyn ByteStream>> - TLS, SOCKS5, Noise
  • ClientLayer<Box<dyn ByteStream>, WsConn<C>> - WebSocket

§Example

use karyon_net::{tcp, tls, ClientLayer, ByteStream, Endpoint};
use karyon_net::tls::ClientTlsConfig;

async {
    let ep: Endpoint = "tcp://127.0.0.1:443".parse().unwrap();
    let stream = tcp::connect(&ep, Default::default()).await.unwrap();
    // let tls_stream: Box<dyn ByteStream> = ClientLayer::handshake(
    //     &tls::TlsLayer::client(config), stream
    // ).await.unwrap();
};

Required Methods§

Source

fn handshake(&self, input: In) -> impl Future<Output = Result<Out>> + Send

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

Source§

impl ClientLayer<Box<dyn ByteStream>, Box<dyn ByteStream>> for Socks5Layer

Source§

impl ClientLayer<Box<dyn ByteStream>, Box<dyn ByteStream>> for TlsLayer

Source§

impl<C> ClientLayer<Box<dyn ByteStream>, WsConn<C>> for WsLayer<C>
where C: Codec<Message> + Clone + Send + Sync + 'static, C::Message: Send + Sync + 'static, C::Error: From<Error> + Into<Error> + Send + Sync,