Struct ServeDir

Source
pub struct ServeDir<FS: AsyncFs = TokioFs> { /* private fields */ }

Implementations§

Source§

impl ServeDir<TokioFs>

Source

pub fn new(path: impl Into<PathBuf>) -> Self

Construct a new ServeDir with given path.

Source§

impl<FS: AsyncFs> ServeDir<FS>

Source

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.

Source

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

Source

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§

Source§

impl<FS: Clone + AsyncFs> Clone for ServeDir<FS>

Source§

fn clone(&self) -> ServeDir<FS>

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.