Struct salvo_core::writing::ReadSeeker
source · pub struct ReadSeeker<R> { /* private fields */ }
Expand description
ReadSeeker
is used to write data to Response
from a reader which implements AsyncRead
and AsyncSeek
.
§Example
use salvo_core::prelude::*;
use salvo_core::writing::ReadSeeker;
#[handler]
async fn video_stream(req: &mut Request, res: &mut Response) {
let file = tokio::fs::File::open("video.mp4").await.unwrap();
res.add_header("Content-Type", "video/mp4", true).unwrap();
let length = file.metadata().await.unwrap().len();
ReadSeeker::new(file, length).send(req.headers(), res).await;
}
Implementations§
source§impl<R> ReadSeeker<R>
impl<R> ReadSeeker<R>
sourcepub fn new(reader: R, length: u64) -> Self
pub fn new(reader: R, length: u64) -> Self
Create a new ReadSeeker
from a reader which implements AsyncRead
and AsyncSeek
.
sourcepub fn last_modified(self, time: SystemTime) -> Self
pub fn last_modified(self, time: SystemTime) -> Self
Set the last modified time for the response.
Trait Implementations§
source§impl<R: Debug> Debug for ReadSeeker<R>
impl<R: Debug> Debug for ReadSeeker<R>
source§impl<R> Writer for ReadSeeker<R>
impl<R> Writer for ReadSeeker<R>
source§fn write<'life0, 'life1, 'life2, 'async_trait>(
self,
req: &'life0 mut Request,
_depot: &'life1 mut Depot,
res: &'life2 mut Response
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn write<'life0, 'life1, 'life2, 'async_trait>(
self,
req: &'life0 mut Request,
_depot: &'life1 mut Depot,
res: &'life2 mut Response
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Write data to
Response
.Auto Trait Implementations§
impl<R> !Freeze for ReadSeeker<R>
impl<R> RefUnwindSafe for ReadSeeker<R>where
R: RefUnwindSafe,
impl<R> Send for ReadSeeker<R>where
R: Send,
impl<R> Sync for ReadSeeker<R>where
R: Sync,
impl<R> Unpin for ReadSeeker<R>where
R: Unpin,
impl<R> UnwindSafe for ReadSeeker<R>where
R: UnwindSafe,
Blanket Implementations§
source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more