Struct rtv::simple::SimpleClient

source ·
pub struct SimpleClient { /* private fields */ }
Expand description

A simpler HTTP client that handles I/O events for you.

The SimpleClient allows you to send requests and read the response using a future. The client is backed by a single reaper thread, that egerly polls mio for new event and processes them. Because of this design the client is fully runtime independent. It even works without any runtime. You could just block_on the future.

Sadly, because the mio::unix::pipe module is used here, the client currently only runs on 64 bit unix systems.

Example

It is really easy to send a single request.

let mut client = SimpleClient::new()?;
let resp = client.send(Request::get("example.com")).await?;
let body_str = String::from_utf8(resp.body); // note: not all websites use UTF-8!
println!("{}", body_str);

Note

Please note that the client currently just panics in a lot of fatal error cases. Most errors should be caught when calling SimpleClient::new though! I plan on adressing this issue soon, so TODO: Fix hard panics on mio/pipe error and error on next stream/send instead

Implementations§

source§

impl SimpleClient

source

pub fn new() -> Result<Self>

Creates a new client

An error is a fatal failure and probably means that the system doesn’t support all necessary functionality.

source

pub fn send( &mut self, input: impl Into<RawRequest> ) -> impl Future<Output = Result<SimpleResponse<Vec<u8>>>>

Send a single request.

This method will send a single request. The returned future does not borrow self.

source

pub fn stream<'d>( &'d mut self, input: impl Into<RawRequest> ) -> impl Future<Output = Result<SimpleResponse<BodyReader>>>

Stream a single request.

This method will send a single request and return a response once the ResponseHead has been transmitted. The response will contain a BodyReader as the body which implements the AsyncRead trait.

You can receive large responses packet-by-packet using this method.

Trait Implementations§

source§

impl Drop for SimpleClient

source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

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, U> TryFrom<U> for T
where U: Into<T>,

§

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>,

§

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.