Struct trillium_proxy::Client

source ·
pub struct Client<C>where
    C: Connector,
{ /* private fields */ }
Expand description

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

Implementations§

source§

impl<C> Client<C>where
    C: Connector,

source

pub fn new() -> Client<C>

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

source

pub fn with_default_pool(self) -> Client<C>

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(); //<-
source

pub fn with_config(self, config: <C as Connector>::Config) -> Client<C>

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()
    });
source

pub fn build_conn<M, U>(&self, method: M, url: U) -> Conn<'_, C>where
    M: TryInto<Method>,
    <M as TryInto<Method>>::Error: Debug,
    U: TryInto<Url>,
    <U as TryInto<Url>>::Error: Debug,

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;
use trillium_testing::prelude::*;
let client = Client::<TcpConnector>::new();

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

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

pub fn get<U>(&self, url: U) -> Conn<'_, C>where
    <U as TryInto<Url>>::Error: Debug,
    U: TryInto<Url>,

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");
source

pub fn post<U>(&self, url: U) -> Conn<'_, C>where
    <U as TryInto<Url>>::Error: Debug,
    U: TryInto<Url>,

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");
source

pub fn put<U>(&self, url: U) -> Conn<'_, C>where
    <U as TryInto<Url>>::Error: Debug,
    U: TryInto<Url>,

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");
source

pub fn delete<U>(&self, url: U) -> Conn<'_, C>where
    <U as TryInto<Url>>::Error: Debug,
    U: TryInto<Url>,

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");
source

pub fn patch<U>(&self, url: U) -> Conn<'_, C>where
    <U as TryInto<Url>>::Error: Debug,
    U: TryInto<Url>,

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§

source§

impl<C> Clone for Client<C>where
    C: Connector,

source§

fn clone(&self) -> Client<C>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<Transport> Debug for Client<Transport>where
    Transport: Connector,

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
source§

impl<C> Default for Client<C>where
    C: Connector,

source§

fn default() -> Client<C>

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

Auto Trait Implementations§

§

impl<C> !RefUnwindSafe for Client<C>

§

impl<C> Send for Client<C>

§

impl<C> Sync for Client<C>

§

impl<C> Unpin for Client<C>where
    <C as Connector>::Config: Unpin,

§

impl<C> !UnwindSafe for Client<C>

Blanket Implementations§

source§

impl<T> Any for Twhere
    T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere
    T: ?Sized,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere
    T: ?Sized,

const: unstable · source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere
    U: From<T>,

const: unstable · source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for Twhere
    T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

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

fn clone_into(&self, target: &mut T)

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

impl<T, U> TryFrom<U> for Twhere
    U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere
    U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
const: unstable · source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.