Skip to main content

Client

Struct Client 

Source
pub struct Client<S> { /* private fields */ }
Expand description

HTTP/1.1 keep-alive connection — pure transport.

Sends request bytes and reads response bytes. All protocol logic lives in RequestWriter (request encoding) and ResponseReader (response parsing).

§Usage

use nexus_web::rest::{Client, RequestWriter};
use nexus_web::http::ResponseReader;
use nexus_web::tls::TlsConfig;

// Protocol (sans-IO)
let mut writer = RequestWriter::new("api.binance.com").unwrap();
let mut reader = ResponseReader::new(32 * 1024);

// Transport
let tls = TlsConfig::new()?;
let mut conn = Client::builder().tls(&tls).connect("https://api.binance.com")?;

// Build + send
let req = writer.get("/orders").query("symbol", "BTC").finish()?;
let resp = conn.send(req, &mut reader)?;

Implementations§

Source§

impl Client<TcpStream>

Source

pub fn builder() -> ClientBuilder

Create a transport builder.

Source

pub fn set_read_timeout( &self, timeout: Option<Duration>, ) -> Result<(), RestError>

Set read timeout on the socket.

Strongly recommended for production. Without a timeout, reads block indefinitely on stale connections.

Source

pub fn set_tcp_keepalive(&self, idle: Duration) -> Result<(), RestError>

Set TCP keepalive on the underlying socket.

Enables OS-level dead connection detection. The kernel sends probes after idle of inactivity.

Source§

impl<S> Client<S>

Source

pub fn new(stream: S) -> Self

Wrap a pre-connected stream.

Source

pub fn is_poisoned(&self) -> bool

Whether the connection is poisoned (I/O error occurred).

Source

pub fn stream(&self) -> &S

Access the underlying stream.

Source

pub fn stream_mut(&mut self) -> &mut S

Mutable access to the underlying stream.

Source§

impl<S: Read + Write> Client<S>

Source

pub fn send<'r>( &mut self, req: Request<'_>, reader: &'r mut ResponseReader, ) -> Result<RestResponse<'r>, RestError>

Send a request and read the response.

req provides the outbound bytes (from RequestWriter). reader receives and parses the response (body size limit configured on the reader via ResponseReader::max_body_size).

Read timeout is a stream-level concern — configure via the builder (read_timeout) or conn.stream().set_read_timeout() for TcpStream. Without a timeout, reads block indefinitely.

Response borrows from reader — drop before next send.

Auto Trait Implementations§

§

impl<S> Freeze for Client<S>
where S: Freeze,

§

impl<S> RefUnwindSafe for Client<S>
where S: RefUnwindSafe,

§

impl<S> Send for Client<S>
where S: Send,

§

impl<S> Sync for Client<S>
where S: Sync,

§

impl<S> Unpin for Client<S>
where S: Unpin,

§

impl<S> UnsafeUnpin for Client<S>
where S: UnsafeUnpin,

§

impl<S> UnwindSafe for Client<S>
where S: UnwindSafe,

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

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

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> Same for T

Source§

type Output = T

Should always be Self
Source§

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

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.
Source§

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

Source§

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

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V