Struct gotham::handler::FileOptions

source ·
pub struct FileOptions { /* private fields */ }
Expand description

Options to pass to file or dir handlers. Allows overriding default behaviour for compression, cache control headers, etc.

FileOptions implements From for String and PathBuf (and related reference types) - so that a path can be passed to router builder methods if only default options are required.

For overridding default options, FileOptions provides builder methods. The default values and use of the builder methods are shown in the example below.


let default_options = FileOptions::from("my_static_path");
let from_builder = FileOptions::new("my_static_path")
    .with_cache_control("public")
    .with_gzip(false)
    .with_brotli(false)
    .build();

assert_eq!(default_options, from_builder);

Implementations§

source§

impl FileOptions

source

pub fn new<P: AsRef<Path>>(path: P) -> Selfwhere PathBuf: From<P>,

Create a new FileOptions with default values.

source

pub fn with_cache_control(&mut self, cache_control: &str) -> &mut Self

Sets the “cache_control” header in static file responses to the given value.

source

pub fn with_gzip(&mut self, gzip: bool) -> &mut Self

If true, given a request for FILE, serves FILE.gz if it exists in the static directory and if the accept-encoding header is set to allow gzipped content (defaults to false).

source

pub fn with_brotli(&mut self, brotli: bool) -> &mut Self

If true, given a request for FILE, serves FILE.br if it exists in the static directory and if the accept-encoding header is set to allow brotli content (defaults to false).

source

pub fn build(&mut self) -> Self

Clones self to return an owned value for passing to a handler.

Trait Implementations§

source§

impl Clone for FileOptions

source§

fn clone(&self) -> FileOptions

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
source§

impl Debug for FileOptions

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl From<&Path> for FileOptions

source§

fn from(t: &Path) -> FileOptions

Converts to this type from the input type.
source§

impl From<&String> for FileOptions

source§

fn from(t: &String) -> FileOptions

Converts to this type from the input type.
source§

impl From<&str> for FileOptions

source§

fn from(t: &str) -> FileOptions

Converts to this type from the input type.
source§

impl From<PathBuf> for FileOptions

source§

fn from(t: PathBuf) -> FileOptions

Converts to this type from the input type.
source§

impl From<String> for FileOptions

source§

fn from(t: String) -> FileOptions

Converts to this type from the input type.
source§

impl PartialEq<FileOptions> for FileOptions

source§

fn eq(&self, other: &FileOptions) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Eq for FileOptions

source§

impl StructuralEq for FileOptions

source§

impl StructuralPartialEq for FileOptions

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

source§

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

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for Twhere 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 Twhere T: Clone,

§

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 Twhere U: Into<T>,

§

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 Twhere U: TryFrom<T>,

§

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.
source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more