Trait SourceStream

Source
pub trait SourceStream:
    TryStream<Ok = Bytes>
    + Stream<Item = Result<Self::Ok, Self::Error>>
    + Unpin
    + Send
    + Sync
    + Sized
    + 'static {
    type Params: Send;
    type StreamCreationError: DecodeError + Send;

    // Required methods
    fn create(
        params: Self::Params,
    ) -> impl Future<Output = Result<Self, Self::StreamCreationError>> + Send;
    fn content_length(&self) -> Option<u64>;
    fn seek_range(
        &mut self,
        start: u64,
        end: Option<u64>,
    ) -> impl Future<Output = Result<()>> + Send;
    fn reconnect(
        &mut self,
        current_position: u64,
    ) -> impl Future<Output = Result<()>> + Send;
    fn supports_seek(&self) -> bool;

    // Provided method
    fn on_finish(
        &mut self,
        result: Result<()>,
        outcome: StreamOutcome,
    ) -> impl Future<Output = Result<()>> + Send { ... }
}
Expand description

Represents a remote resource that can be streamed over the network. Streaming over http is implemented via the HttpStream implementation if the http feature is enabled.

The implementation must also implement the Stream trait.

Required Associated Types§

Source

type Params: Send

Parameters used to create the remote resource.

Source

type StreamCreationError: DecodeError + Send

Error type thrown when creating the stream.

Required Methods§

Source

fn create( params: Self::Params, ) -> impl Future<Output = Result<Self, Self::StreamCreationError>> + Send

Creates an instance of the stream.

Source

fn content_length(&self) -> Option<u64>

Returns the size of the remote resource in bytes. The result should be None if the stream is infinite or doesn’t have a known length.

Source

fn seek_range( &mut self, start: u64, end: Option<u64>, ) -> impl Future<Output = Result<()>> + Send

Seeks to a specific position in the stream. This method is only called if the requested range has not been downloaded, so this method should jump to the requested position in the stream as quickly as possible.

The start value should be inclusive and the end value should be exclusive.

Source

fn reconnect( &mut self, current_position: u64, ) -> impl Future<Output = Result<()>> + Send

Attempts to reconnect to the server when a failure occurs.

Source

fn supports_seek(&self) -> bool

Returns whether seeking is supported in the stream. If this method returns false, SourceStream::seek_range will never be invoked.

Provided Methods§

Source

fn on_finish( &mut self, result: Result<()>, outcome: StreamOutcome, ) -> impl Future<Output = Result<()>> + Send

Called when the stream finishes downloading

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 SourceStream for ProcessStream

Available on crate feature process only.
Source§

impl<C: Client> SourceStream for HttpStream<C>

Available on crate feature http only.
Source§

impl<T> SourceStream for AsyncReadStream<T>
where T: AsyncRead + Send + Sync + Unpin + 'static,

Available on crate feature async-read only.