Skip to main content

Fetcher

Trait Fetcher 

Source
pub trait Fetcher: Send + Sync {
    // Required method
    fn fetch<'life0, 'async_trait>(
        &'life0 self,
        req: FetchRequest,
    ) -> Pin<Box<dyn Future<Output = Result<String, FetchError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;

    // Provided method
    fn fetch_full<'life0, 'async_trait>(
        &'life0 self,
        req: FetchRequest,
    ) -> Pin<Box<dyn Future<Output = Result<FetchResponse, FetchError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait { ... }
}
Expand description

取页抽象。实现者负责发请求 + 按目标站字符集解码为文本。

Required Methods§

Source

fn fetch<'life0, 'async_trait>( &'life0 self, req: FetchRequest, ) -> Pin<Box<dyn Future<Output = Result<String, FetchError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

取一个页面的解码后文本。

Provided Methods§

Source

fn fetch_full<'life0, 'async_trait>( &'life0 self, req: FetchRequest, ) -> Pin<Box<dyn Future<Output = Result<FetchResponse, FetchError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

取完整响应(body + 状态码 + 响应头)。默认仅回 body(状态 200、头为空); 需要 headers/状态码的实现(如 ReqwestFetcher)应覆盖本方法。

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§