pub struct Downloader { /* private fields */ }
Expand description

Represents a downloader that can be used to download resources over HTTP/HTTPS.

Implementations§

source§

impl Downloader

source

pub fn new() -> Self

Creates a new Downloader.

source

pub fn use_uri(&mut self, uri: Uri) -> &mut Self

Sets the URI to download from.

Arguments
  • uri - The URI to download from.
Examples
extern crate tokio;
extern crate download_async;

#[tokio::main]
async fn main() {
  let uri = download_async::http::Uri::from_static("https://www.example.com");
  let mut downloader = download_async::Downloader::new();
  downloader.use_uri(uri);
  let mut buffer = vec![];
  let response = downloader.download(download_async::Body::empty(), &mut buffer).await;
}
source

pub fn headers(&mut self) -> Option<&mut HeaderMap<HeaderValue>>

Gets a mutable reference to the headers map for the request.

source

pub fn use_sockets(&mut self, sockets: SocketAddrs) -> &mut Self

Sets the SocketAddrs to use for the request.

Arguments
  • sockets - The SocketAddrs to use for the request.
source

pub fn allow_http(&mut self) -> &mut Self

Allows HTTP requests in addition to HTTPS requests.

Examples
extern crate tokio;
extern crate download_async;

#[tokio::main]
async fn main() {
  let uri = download_async::http::Uri::from_static("https://www.example.com");
  let mut downloader = download_async::Downloader::new();
  downloader.use_uri(uri);
  downloader.allow_http();
  let mut buffer = vec![];
  let response = downloader.download(download_async::Body::empty(), &mut buffer).await;
}
source

pub fn use_progress<T: Progress + Send + 'static>( &mut self, progress: T ) -> &mut Self

source

pub fn disable_compression(&mut self) -> &mut Self

Sends the server the appropriate headers to prevent response compression.

Examples
extern crate tokio;
extern crate download_async;

#[tokio::main]
async fn main() {
  let uri = download_async::http::Uri::from_static("https://www.example.com");
  let mut downloader = download_async::Downloader::new();
  downloader.use_uri(uri);
  downloader.disable_compression();
  let mut buffer = vec![];
  let response = downloader.download(download_async::Body::empty(), &mut buffer).await;
}
source

pub async fn download<T: HttpBody + Send + 'static>( self, body: T, to: &mut impl Write ) -> Result<Parts, Error>where T::Data: Send, T::Error: Into<Box<dyn Error + Send + Sync>>,

An async method to download a resource and write it to a writer

Arguments
  • self - The Downloader instance to use for the request
  • body - The request body
  • to - A mutable reference to the writer to write the downloaded data to
Returns

A Result containing Parts if successful, or an Error if there was an issue with the download

Generic Parameters
  • T - The type of HttpBody to use for the request
Constraints
  • T must implement HttpBody, Send, and 'static
  • T::Data must implement Send
  • T::Error must implement Into<BoxError>
Examples
extern crate tokio;
extern crate download_async;

#[tokio::main]
async fn main() {
  let uri = download_async::http::Uri::from_static("https://www.example.com");
  let mut downloader = download_async::Downloader::new();
  downloader.use_uri(uri);
  downloader.allow_http();
  let mut buffer = vec![];
  let response = downloader.download(download_async::Body::empty(), &mut buffer).await;
}

Auto Trait Implementations§

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

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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, 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.
source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more