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
sourceimpl<C> Client<C> where
C: Connector,
impl<C> Client<C> where
C: Connector,
sourcepub fn new() -> Client<C>
pub fn new() -> Client<C>
Constructs a new Client without a connection pool and with default configuration.
sourcepub fn with_default_pool(self) -> Client<C>
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(); //<-
sourcepub fn with_config(self, config: <C as Connector>::Config) -> Client<C>
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()
});
sourcepub fn build_conn<M, U>(&self, method: M, url: U) -> Conn<'_, C> where
M: TryInto<Method>,
U: TryInto<Url>,
<M as TryInto<Method>>::Error: Debug,
<U as TryInto<Url>>::Error: Debug,
pub fn build_conn<M, U>(&self, method: M, url: U) -> Conn<'_, C> where
M: TryInto<Method>,
U: TryInto<Url>,
<M as TryInto<Method>>::Error: Debug,
<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");
sourcepub fn get<U>(&self, url: U) -> Conn<'_, C> where
U: TryInto<Url>,
<U as TryInto<Url>>::Error: Debug,
pub fn get<U>(&self, url: U) -> Conn<'_, C> where
U: TryInto<Url>,
<U as TryInto<Url>>::Error: Debug,
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");
sourcepub fn post<U>(&self, url: U) -> Conn<'_, C> where
U: TryInto<Url>,
<U as TryInto<Url>>::Error: Debug,
pub fn post<U>(&self, url: U) -> Conn<'_, C> where
U: TryInto<Url>,
<U as TryInto<Url>>::Error: Debug,
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");
sourcepub fn put<U>(&self, url: U) -> Conn<'_, C> where
U: TryInto<Url>,
<U as TryInto<Url>>::Error: Debug,
pub fn put<U>(&self, url: U) -> Conn<'_, C> where
U: TryInto<Url>,
<U as TryInto<Url>>::Error: Debug,
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");
sourcepub fn delete<U>(&self, url: U) -> Conn<'_, C> where
U: TryInto<Url>,
<U as TryInto<Url>>::Error: Debug,
pub fn delete<U>(&self, url: U) -> Conn<'_, C> where
U: TryInto<Url>,
<U as TryInto<Url>>::Error: Debug,
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");
sourcepub fn patch<U>(&self, url: U) -> Conn<'_, C> where
U: TryInto<Url>,
<U as TryInto<Url>>::Error: Debug,
pub fn patch<U>(&self, url: U) -> Conn<'_, C> where
U: TryInto<Url>,
<U as TryInto<Url>>::Error: Debug,
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
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
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcefn clone_into(&self, target: &mut T)
fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more