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§
Sourcetype StreamCreationError: DecodeError + Send
type StreamCreationError: DecodeError + Send
Error type thrown when creating the stream.
Required Methods§
Sourcefn create(
params: Self::Params,
) -> impl Future<Output = Result<Self, Self::StreamCreationError>> + Send
fn create( params: Self::Params, ) -> impl Future<Output = Result<Self, Self::StreamCreationError>> + Send
Creates an instance of the stream.
Sourcefn content_length(&self) -> Option<u64>
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.
Sourcefn seek_range(
&mut self,
start: u64,
end: Option<u64>,
) -> impl Future<Output = Result<()>> + Send
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.
Sourcefn reconnect(
&mut self,
current_position: u64,
) -> impl Future<Output = Result<()>> + Send
fn reconnect( &mut self, current_position: u64, ) -> impl Future<Output = Result<()>> + Send
Attempts to reconnect to the server when a failure occurs.
Sourcefn supports_seek(&self) -> bool
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§
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.
impl SourceStream for ProcessStream
process
only.Source§impl<C: Client> SourceStream for HttpStream<C>
Available on crate feature http
only.
impl<C: Client> SourceStream for HttpStream<C>
http
only.type Params = <C as Client>::Url
type StreamCreationError = HttpStreamError<C>
Source§impl<T> SourceStream for AsyncReadStream<T>
Available on crate feature async-read
only.
impl<T> SourceStream for AsyncReadStream<T>
async-read
only.