Skip to main content

StdCompatConnect

Trait StdCompatConnect 

Source
pub trait StdCompatConnect: Sized {
    // Required methods
    fn connect_v4(address: &str, port: u16) -> Result<Self, SocketError>;
    fn connect_v6(address: &str, port: u16) -> Result<Self, SocketError>;

    // Provided method
    fn connect(address: &str, port: u16) -> Result<Self, SocketError> { ... }
}
Expand description

A trait used for convenience; import it so that the code remains consistent with the std version (with the only difference being the return error type).

Take TcpStream as example:

use optee_utee::net::{Setup, TcpStream, SocketError};

fn connect_without_compact_trait(host: &str, port: u16) -> Result<TcpStream, SocketError> {
    let setup = Setup::new_v4(host, port)?;
    TcpStream::open(setup)
}

fn connect_with_compact_trait(host: &str, port: u16) {
    // `as _` imports the trait for method resolution only: under `std`
    // the inherent `connect_v4` below wins, under no-std the trait
    // method does. Either way the call shape is one line; only the
    // error type differs, so the result is discarded here instead of
    // being annotated.
    use optee_utee::net::StdCompatConnect as _;

    let _ = TcpStream::connect_v4(host, port);
}

Required Methods§

Source

fn connect_v4(address: &str, port: u16) -> Result<Self, SocketError>

Source

fn connect_v6(address: &str, port: u16) -> Result<Self, SocketError>

Provided Methods§

Source

fn connect(address: &str, port: u16) -> Result<Self, SocketError>

Dyn Compatibility§

This trait is not dyn compatible.

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

Implementors§