Skip to main content

Entity

Trait Entity 

Source
pub trait Entity:
    'static
    + Send
    + Sync {
    type Error: 'static + Send + Sync;
    type Data: 'static + Send + Sync + Buf + From<Vec<u8>> + From<&'static [u8]>;

    // Required methods
    fn len(&self) -> u64;
    fn get_range(
        &self,
        range: Range<u64>,
    ) -> Box<dyn Stream<Item = Result<Self::Data, Self::Error>> + Send + Sync>;
    fn add_headers(&self, _: &mut HeaderMap);
    fn etag(&self) -> Option<HeaderValue>;
    fn last_modified(&self) -> Option<SystemTime>;

    // Provided method
    fn is_empty(&self) -> bool { ... }
}
Expand description

A reusable, read-only, byte-rangeable HTTP entity for GET and HEAD serving. Must return exactly the same data on every call.

Required Associated Types§

Source

type Error: 'static + Send + Sync

Source

type Data: 'static + Send + Sync + Buf + From<Vec<u8>> + From<&'static [u8]>

The type of a data chunk.

Commonly bytes::Bytes but may be something more exotic.

Required Methods§

Source

fn len(&self) -> u64

Returns the length of the entity’s body in bytes.

Source

fn get_range( &self, range: Range<u64>, ) -> Box<dyn Stream<Item = Result<Self::Data, Self::Error>> + Send + Sync>

Gets the body bytes indicated by range.

Source

fn add_headers(&self, _: &mut HeaderMap)

Adds entity headers such as Content-Type to the supplied Headers object. In particular, these headers are the “other representation header fields” described by RFC 7233 section 4.1; they should exclude Content-Range, Date, Cache-Control, ETag, Expires, Content-Location, and Vary.

This function will be called only when that section says that headers such as Content-Type should be included in the response.

Source

fn etag(&self) -> Option<HeaderValue>

Returns an etag for this entity, if available. Implementations are encouraged to provide a strong etag. RFC 7232 section 2.1 notes that only strong etags are usable for sub-range retrieval.

Source

fn last_modified(&self) -> Option<SystemTime>

Returns the last modified time of this entity, if available. Note that serve may serve an earlier Last-Modified: date than the one returned here if this time is in the future, as required by RFC 7232 section 2.2.1.

Provided Methods§

Source

fn is_empty(&self) -> bool

Returns true iff the entity’s body has length 0.

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§

Source§

impl<D, E> Entity for ChunkedReadFile<D, E>
where D: 'static + Send + Sync + Buf + From<Vec<u8>> + From<&'static [u8]>, E: 'static + Send + Sync + Into<Box<dyn StdError + Send + Sync>> + From<Box<dyn StdError + Send + Sync>>,

Source§

type Data = D

Source§

type Error = E