pub struct ServeDir<FS: AsyncFs = TokioFs> { /* private fields */ }
Implementations§
Source§impl<FS: AsyncFs> ServeDir<FS>
impl<FS: AsyncFs> ServeDir<FS>
Sourcepub fn with_fs(path: impl Into<PathBuf>, async_fs: FS) -> Self
pub fn with_fs(path: impl Into<PathBuf>, async_fs: FS) -> Self
construct a new ServeDir with given path and async file system type. The type must impl AsyncFs trait for properly handling file streaming.
Sourcepub fn chunk_size(&mut self, size: usize) -> &mut Self
pub fn chunk_size(&mut self, size: usize) -> &mut Self
hint for chunk size of async file streaming. it’s a best effort upper bound and should not be trusted to produce exact chunk size as under/over shoot can happen
Sourcepub async fn serve<Ext>(
&self,
req: &Request<Ext>,
) -> Result<Response<ChunkReader<FS::File>>, ServeError>
pub async fn serve<Ext>( &self, req: &Request<Ext>, ) -> Result<Response<ChunkReader<FS::File>>, ServeError>
try to find a matching file from given input request and generate http response with stream reader of matched file.
§Examples
async fn serve(req: &Request<()>) {
let dir = ServeDir::new("sample");
let res = dir.serve(&req).await;
}
Trait Implementations§
Auto Trait Implementations§
impl<FS> Freeze for ServeDir<FS>where
FS: Freeze,
impl<FS> RefUnwindSafe for ServeDir<FS>where
FS: RefUnwindSafe,
impl<FS> Send for ServeDir<FS>where
FS: Send,
impl<FS> Sync for ServeDir<FS>where
FS: Sync,
impl<FS> Unpin for ServeDir<FS>where
FS: Unpin,
impl<FS> UnwindSafe for ServeDir<FS>where
FS: UnwindSafe,
Blanket Implementations§
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