Struct trillium_proxy::Client[][src]

pub struct Client<C> where
    C: Connector
{ /* fields omitted */ }
Expand description

A client contains a Config and an optional connection pool and builds conns.

Implementations

Constructs a new Client without a connection pool and with default configuration.

chainable constructor to enable connection pooling. this can be combined with Client::with_config

use trillium_smol::TcpConnector;
use trillium_client::Client;

let client = Client::<TcpConnector>::new()
    .with_default_pool(); //<-

chainable constructor to specify Connector configuration. this can be combined with Client::with_default_pool

use trillium_smol::{TcpConnector, ClientConfig};
use trillium_client::Client;

let client = Client::<TcpConnector>::new()
    .with_config(ClientConfig { //<-
        nodelay: Some(true),
        ..Default::default()
    });

builds a new conn borrowing the config on this client. if the client has pooling enabled and there is an available connection to the dns-resolved socket (ip and port), the new conn will reuse that when it is sent.

use trillium_smol::{TcpConnector, ClientConfig};
use trillium_client::Client;
let client = Client::<TcpConnector>::new();

let conn = client.build_conn("get", "http://trillium.rs"); //<-

assert_eq!(conn.method(), trillium_testing::Method::Get);
assert_eq!(conn.url().host_str().unwrap(), "trillium.rs");

Builds a new client conn with the get http method and the provided url.

let client = Client::<TcpConnector>::new();
let conn = client.get("http://localhost:8080/some/route"); //<-

assert_eq!(conn.method(), Method::Get);
assert_eq!(conn.url().to_string(), "http://localhost:8080/some/route");

Builds a new client conn with the post http method and the provided url.

let client = Client::<TcpConnector>::new();
let conn = client.post("http://localhost:8080/some/route"); //<-

assert_eq!(conn.method(), Method::Post);
assert_eq!(conn.url().to_string(), "http://localhost:8080/some/route");

Builds a new client conn with the put http method and the provided url.

let client = Client::<TcpConnector>::new();
let conn = client.put("http://localhost:8080/some/route"); //<-

assert_eq!(conn.method(), Method::Put);
assert_eq!(conn.url().to_string(), "http://localhost:8080/some/route");

Builds a new client conn with the delete http method and the provided url.

let client = Client::<TcpConnector>::new();
let conn = client.delete("http://localhost:8080/some/route"); //<-

assert_eq!(conn.method(), Method::Delete);
assert_eq!(conn.url().to_string(), "http://localhost:8080/some/route");

Builds a new client conn with the patch http method and the provided url.

let client = Client::<TcpConnector>::new();
let conn = client.patch("http://localhost:8080/some/route"); //<-

assert_eq!(conn.method(), Method::Patch);
assert_eq!(conn.url().to_string(), "http://localhost:8080/some/route");

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Returns the “default value” for a type. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.