Trait Download

Source
pub trait Download {
    type Err<'dst>;
    type Fut<'dst>: Future<Output = Result<(), Self::Err<'dst>>> + Send;
    type StreamErr;
    type Stream: Stream<Item = Result<Bytes, Self::StreamErr>> + Send;

    // Required methods
    fn download_file<'dst>(
        &self,
        path: &str,
        destination: &'dst mut (dyn AsyncWrite + Unpin + Send),
    ) -> Self::Fut<'dst>;
    fn download_file_stream(&self, path: &str) -> Self::Stream;
}
Expand description

A trait for downloading files from Telegram.

Required Associated Types§

Source

type Err<'dst>

An error returned from download_file.

Source

type Fut<'dst>: Future<Output = Result<(), Self::Err<'dst>>> + Send

A future returned from download_file.

Source

type StreamErr

An error returned from download_file_stream.

Source

type Stream: Stream<Item = Result<Bytes, Self::StreamErr>> + Send

A stream returned from download_file_stream.

Required Methods§

Source

fn download_file<'dst>( &self, path: &str, destination: &'dst mut (dyn AsyncWrite + Unpin + Send), ) -> Self::Fut<'dst>

Download a file from Telegram into destination.

path can be obtained from GetFile.

To download as a stream of chunks, see download_file_stream.

§Examples
use teloxide_core::{
    net::Download,
    requests::{Request, Requester},
    types::File,
    Bot,
};
use tokio::fs;

let bot = Bot::new("TOKEN");

let file = bot.get_file("*file_id*").await?;
let mut dst = fs::File::create("/tmp/test.png").await?;
bot.download_file(&file.path, &mut dst).await?;
Source

fn download_file_stream(&self, path: &str) -> Self::Stream

Download a file from Telegram as Stream.

path can be obtained from the GetFile.

To download into an AsyncWrite (e.g. tokio::fs::File), see download_file.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl Download for Bot

Source§

type Err<'dst> = DownloadError

Source§

type Fut<'dst> = Pin<Box<dyn Future<Output = Result<(), DownloadError>> + Send + 'dst>>

Source§

type StreamErr = Error

Source§

type Stream = Pin<Box<dyn Stream<Item = Result<Bytes, Error>> + Send>>

Source§

impl<B: Download> Download for CacheMe<B>

Available on crate feature cache_me only.
Source§

type Err<'dst> = <B as Download>::Err<'dst>

Source§

type Fut<'dst> = <B as Download>::Fut<'dst>

Source§

type StreamErr = <B as Download>::StreamErr

Source§

type Stream = <B as Download>::Stream

Source§

impl<B: Download> Download for DefaultParseMode<B>

Source§

type Err<'dst> = <B as Download>::Err<'dst>

Source§

type Fut<'dst> = <B as Download>::Fut<'dst>

Source§

type StreamErr = <B as Download>::StreamErr

Source§

type Stream = <B as Download>::Stream

Source§

impl<B: Download> Download for Throttle<B>

Available on crate feature throttle only.
Source§

type Err<'dst> = <B as Download>::Err<'dst>

Source§

type Fut<'dst> = <B as Download>::Fut<'dst>

Source§

type StreamErr = <B as Download>::StreamErr

Source§

type Stream = <B as Download>::Stream