Struct rocket::fs::Options

source ·
pub struct Options(_);
Expand description

A bitset representing configurable options for FileServer.

The valid options are:

Options structures can be ord together to select two or more options. For instance, to request that both dot files and index pages be returned, use Options::DotFiles | Options::Index.

Implementations§

source§

impl Options

source

pub const None: Options = _

All options disabled.

This is different than Options::default(), which enables Options::Index.

source

pub const Index: Options = _

Respond to requests for a directory with the index.html file in that directory, if it exists.

When enabled, FileServer will respond to requests for a directory /foo or /foo/ with the file at ${root}/foo/index.html if it exists. When disabled, requests to directories will always forward.

Enabled by default.

source

pub const DotFiles: Options = _

Allow serving dotfiles.

When enabled, FileServer will respond to requests for files or directories beginning with .. When disabled, any dotfiles will be treated as missing.

Disabled by default.

source

pub const NormalizeDirs: Options = _

Normalizes directory requests by redirecting requests to directory paths without a trailing slash to ones with a trailing slash.

When enabled, the FileServer handler will respond to requests for a directory without a trailing / with a permanent redirect (308) to the same path with a trailing /. This ensures relative URLs within any document served from that directory will be interpreted relative to that directory rather than its parent.

Disabled by default.

Example

Given the following directory structure…

static/
└── foo/
    ├── cat.jpeg
    └── index.html

…with FileServer::from("static"), both requests to /foo and /foo/ will serve static/foo/index.html. If index.html references cat.jpeg as a relative URL, the browser will request /cat.jpeg (static/cat.jpeg) when the request for /foo was handled and /foo/cat.jpeg (static/foo/cat.jpeg) if /foo/ was handled. As a result, the request in the former case will fail. To avoid this, NormalizeDirs will redirect requests to /foo to /foo/ if the file that would be served is a directory.

source

pub const IndexFile: Options = _

Allow serving a file instead of a directory.

By default, FileServer will error on construction if the path to serve does not point to a directory. When this option is enabled, if a path to a file is provided, FileServer will serve the file as the root of the mount path.

Example

If the file tree looks like:

static/
└── cat.jpeg

Then cat.jpeg can be served at /cat with:

use rocket::fs::{FileServer, Options};

#[launch]
fn rocket() -> _ {
    rocket::build()
        .mount("/cat", FileServer::new("static/cat.jpeg", Options::IndexFile))
}
source

pub const Missing: Options = _

Don’t fail if the file or directory to serve is missing.

By default, FileServer will error if the path to serve is missing to prevent inevitable 404 errors. This option overrides that.

source

pub fn contains(self, other: Options) -> bool

Returns true if self is a superset of other. In other words, returns true if all of the options in other are also in self.

Example
use rocket::fs::Options;

let index_request = Options::Index | Options::DotFiles;
assert!(index_request.contains(Options::Index));
assert!(index_request.contains(Options::DotFiles));

let index_only = Options::Index;
assert!(index_only.contains(Options::Index));
assert!(!index_only.contains(Options::DotFiles));

let dot_only = Options::DotFiles;
assert!(dot_only.contains(Options::DotFiles));
assert!(!dot_only.contains(Options::Index));

Trait Implementations§

source§

impl BitOr<Options> for Options

§

type Output = Options

The resulting type after applying the | operator.
source§

fn bitor(self, rhs: Self) -> Self

Performs the | operation. Read more
source§

impl Clone for Options

source§

fn clone(&self) -> Options

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 Options

source§

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

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

impl Default for Options

The default set of options: Options::Index.

source§

fn default() -> Self

Returns the “default value” for a type. Read more
source§

impl Copy for Options

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
§

impl<'a, T> AsTaggedExplicit<'a> for Twhere T: 'a,

§

fn explicit(self, class: Class, tag: u32) -> TaggedParser<'a, Explicit, Self>

§

impl<'a, T> AsTaggedImplicit<'a> for Twhere T: 'a,

§

fn implicit( self, class: Class, constructed: bool, tag: u32 ) -> TaggedParser<'a, Implicit, Self>

source§

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

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

const: unstable · source§

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

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · 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>,

const: unstable · 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.

§

impl<T> IntoCollection<T> for T

§

fn into_collection<A>(self) -> SmallVec<A>where A: Array<Item = T>,

Converts self into a collection.
§

fn mapped<U, F, A>(self, f: F) -> SmallVec<A>where F: FnMut(T) -> U, A: Array<Item = U>,

source§

impl<T> Same<T> for T

§

type Output = T

Should always be Self
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.
const: unstable · 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.
const: unstable · source§

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

Performs the conversion.
§

impl<V, T> VZip<V> for Twhere V: MultiLane<T>,

§

fn vzip(self) -> V

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