pub struct Options(/* private fields */);
Expand description
A bitset representing configurable options for FileServer
.
The valid options are:
Options::None
- Return only present, visible files.Options::DotFiles
- In addition to visible files, return dotfiles.Options::Index
- Renderindex.html
pages for directory requests.Options::IndexFile
- Allow serving a single file as the index.Options::Missing
- Don’t fail if the path to serve is missing.Options::NormalizeDirs
- Redirect directories without a trailing slash to ones with a trailing slash.
Options
structures can be or
d 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
impl Options
sourcepub const None: Options = _
pub const None: Options = _
All options disabled.
Note that this is different than Options::default()
,
which enables options.
sourcepub const Index: Options = _
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.
sourcepub const DotFiles: Options = _
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.
sourcepub const NormalizeDirs: Options = _
pub const NormalizeDirs: Options = _
Normalizes directory requests by redirecting requests to directory paths without a trailing slash to ones with a trailing slash.
Enabled by default.
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.
Example
Given the following directory structure…
static/
└── foo/
├── cat.jpeg
└── index.html
And the following server:
rocket.mount("/", FileServer::from("static"))
…requests to example.com/foo
will be redirected to
example.com/foo/
. If index.html
references cat.jpeg
as a relative
URL, the browser will resolve the URL to example.com/foo/cat.jpeg
,
which in-turn Rocket will match to /static/foo/cat.jpg
.
Without this option, requests to example.com/foo
would not be
redirected. index.html
would be rendered, and the relative link to
cat.jpeg
would be resolved by the browser as example.com/cat.jpeg
.
Rocket would thus try to find /static/cat.jpeg
, which does not exist.
sourcepub const IndexFile: Options = _
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))
}
sourcepub const Missing: Options = _
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.
sourcepub fn contains(self, other: Options) -> bool
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§
impl Copy for Options
Auto Trait Implementations§
impl RefUnwindSafe for Options
impl Send for Options
impl Sync for Options
impl Unpin for Options
impl UnwindSafe for Options
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
source§impl<T> Instrument for T
impl<T> Instrument for T
source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
source§impl<T> IntoCollection<T> for T
impl<T> IntoCollection<T> for T
source§impl<T> Paint for Twhere
T: ?Sized,
impl<T> Paint for Twhere T: ?Sized,
source§fn fg(&self, value: Color) -> Painted<&T>
fn fg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self
with the foreground set to
value
.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like red()
and
green()
, which have the same functionality but are
pithier.
Example
Set foreground color to white using fg()
:
use yansi::{Paint, Color};
painted.fg(Color::White);
Set foreground color to white using white()
.
use yansi::Paint;
painted.white();
source§fn bright_black(&self) -> Painted<&T>
fn bright_black(&self) -> Painted<&T>
source§fn bright_red(&self) -> Painted<&T>
fn bright_red(&self) -> Painted<&T>
source§fn bright_green(&self) -> Painted<&T>
fn bright_green(&self) -> Painted<&T>
source§fn bright_yellow(&self) -> Painted<&T>
fn bright_yellow(&self) -> Painted<&T>
Returns self
with the
fg()
set to
Color::BrightYellow
.
Example
println!("{}", value.bright_yellow());
source§fn bright_blue(&self) -> Painted<&T>
fn bright_blue(&self) -> Painted<&T>
source§fn bright_magenta(&self) -> Painted<&T>
fn bright_magenta(&self) -> Painted<&T>
Returns self
with the
fg()
set to
Color::BrightMagenta
.
Example
println!("{}", value.bright_magenta());
source§fn bright_cyan(&self) -> Painted<&T>
fn bright_cyan(&self) -> Painted<&T>
source§fn bright_white(&self) -> Painted<&T>
fn bright_white(&self) -> Painted<&T>
source§fn bg(&self, value: Color) -> Painted<&T>
fn bg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self
with the background set to
value
.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like on_red()
and
on_green()
, which have the same functionality but
are pithier.
Example
Set background color to red using fg()
:
use yansi::{Paint, Color};
painted.bg(Color::Red);
Set background color to red using on_red()
.
use yansi::Paint;
painted.on_red();
source§fn on_primary(&self) -> Painted<&T>
fn on_primary(&self) -> Painted<&T>
source§fn on_magenta(&self) -> Painted<&T>
fn on_magenta(&self) -> Painted<&T>
source§fn on_bright_black(&self) -> Painted<&T>
fn on_bright_black(&self) -> Painted<&T>
Returns self
with the
bg()
set to
Color::BrightBlack
.
Example
println!("{}", value.on_bright_black());
source§fn on_bright_red(&self) -> Painted<&T>
fn on_bright_red(&self) -> Painted<&T>
source§fn on_bright_green(&self) -> Painted<&T>
fn on_bright_green(&self) -> Painted<&T>
Returns self
with the
bg()
set to
Color::BrightGreen
.
Example
println!("{}", value.on_bright_green());
source§fn on_bright_yellow(&self) -> Painted<&T>
fn on_bright_yellow(&self) -> Painted<&T>
Returns self
with the
bg()
set to
Color::BrightYellow
.
Example
println!("{}", value.on_bright_yellow());
source§fn on_bright_blue(&self) -> Painted<&T>
fn on_bright_blue(&self) -> Painted<&T>
Returns self
with the
bg()
set to
Color::BrightBlue
.
Example
println!("{}", value.on_bright_blue());
source§fn on_bright_magenta(&self) -> Painted<&T>
fn on_bright_magenta(&self) -> Painted<&T>
Returns self
with the
bg()
set to
Color::BrightMagenta
.
Example
println!("{}", value.on_bright_magenta());
source§fn on_bright_cyan(&self) -> Painted<&T>
fn on_bright_cyan(&self) -> Painted<&T>
Returns self
with the
bg()
set to
Color::BrightCyan
.
Example
println!("{}", value.on_bright_cyan());
source§fn on_bright_white(&self) -> Painted<&T>
fn on_bright_white(&self) -> Painted<&T>
Returns self
with the
bg()
set to
Color::BrightWhite
.
Example
println!("{}", value.on_bright_white());
source§fn attr(&self, value: Attribute) -> Painted<&T>
fn attr(&self, value: Attribute) -> Painted<&T>
Enables the styling Attribute
value
.
This method should be used rarely. Instead, prefer to use
attribute-specific builder methods like bold()
and
underline()
, which have the same functionality
but are pithier.
Example
Make text bold using attr()
:
use yansi::{Paint, Attribute};
painted.attr(Attribute::Bold);
Make text bold using using bold()
.
use yansi::Paint;
painted.bold();
source§fn underline(&self) -> Painted<&T>
fn underline(&self) -> Painted<&T>
Returns self
with the
attr()
set to
Attribute::Underline
.
Example
println!("{}", value.underline());
source§fn rapid_blink(&self) -> Painted<&T>
fn rapid_blink(&self) -> Painted<&T>
Returns self
with the
attr()
set to
Attribute::RapidBlink
.
Example
println!("{}", value.rapid_blink());
source§fn quirk(&self, value: Quirk) -> Painted<&T>
fn quirk(&self, value: Quirk) -> Painted<&T>
Enables the yansi
Quirk
value
.
This method should be used rarely. Instead, prefer to use quirk-specific
builder methods like mask()
and
wrap()
, which have the same functionality but are
pithier.
Example
Enable wrapping using .quirk()
:
use yansi::{Paint, Quirk};
painted.quirk(Quirk::Wrap);
Enable wrapping using wrap()
.
use yansi::Paint;
painted.wrap();
source§fn whenever(&self, value: Condition) -> Painted<&T>
fn whenever(&self, value: Condition) -> Painted<&T>
Conditionally enable styling based on whether the Condition
value
applies. Replaces any previous condition.
See the crate level docs for more details.
Example
Enable styling painted
only when both stdout
and stderr
are TTYs:
use yansi::{Paint, Condition};
painted.red().on_yellow().whenever(Condition::STDOUTERR_ARE_TTY);