logo
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

All options disabled.

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

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.

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.

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.

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))
}

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.

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

The resulting type after applying the | operator.

Performs the | operation. Read more

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

The default set of options: Options::Index.

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

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

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

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

Calls U::from(self).

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

Converts self into a collection.

Should always be Self

The resulting type after obtaining ownership.

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

🔬 This is a nightly-only experimental API. (toowned_clone_into)

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

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

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

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