pub struct Ident(_);
Expand description
An identifier (or None
) to send as the Server
header.
Deserialization
An Ident
deserializes from any of the following:
-
string
The string must be a valid
Ident
. SeeIdent::try_new()
for details. -
boolean
The boolean must be
false
. The value will beIdent::none()
. -
Option<string>
If
Some
, this is the same as deserializing from the inner string. IfNone
, the value isIdent::none()
. -
unit
Always deserializes as
Ident::none()
.
Examples
As with all Rocket configuration options, when using the default
Config::figment()
, Ident
can be configured
via a Rocket.toml
file. When no value for ident
is provided, the value
defaults to "Rocket"
. Because a default is provided, configuration only
needs to provided to customize or remove the value.
use rocket::config::{Config, Ident};
// If these are the contents of `Rocket.toml`...
[default]
ident = false
// The config parses as follows:
assert_eq!(config.ident, Ident::none());
// If these are the contents of `Rocket.toml`...
[default]
ident = "My Server"
// The config parses as follows:
assert_eq!(config.ident, Ident::try_new("My Server").unwrap());
The following example illustrates manual configuration:
use rocket::config::{Config, Ident};
let figment = rocket::Config::figment().merge(("ident", false));
let config = rocket::Config::from(figment);
assert_eq!(config.ident, Ident::none());
let figment = rocket::Config::figment().merge(("ident", "Fancy/1.0"));
let config = rocket::Config::from(figment);
assert_eq!(config.ident, Ident::try_new("Fancy/1.0").unwrap());
Implementations§
source§impl Ident
impl Ident
sourcepub fn try_new<S: Into<String>>(ident: S) -> Result<Ident, String>
pub fn try_new<S: Into<String>>(ident: S) -> Result<Ident, String>
Returns a new Ident
with the string ident
.
When configured as the Config::ident
, Rocket
will set a Server
header with the ident
value on all responses.
Errors
The string ident
must be non-empty and may only contain visible ASCII
characters. The first character cannot be whitespace. The only
whitespace characters allowed are
(space) and \t
(horizontal tab).
The string is returned wrapped in Err
if it contains any invalid
characters.
Example
use rocket::config::Ident;
let ident = Ident::try_new("Rocket").unwrap();
assert_eq!(ident.as_str(), Some("Rocket"));
let ident = Ident::try_new("Rocket Run").unwrap();
assert_eq!(ident.as_str(), Some("Rocket Run"));
let ident = Ident::try_new(" Rocket");
assert!(ident.is_err());
let ident = Ident::try_new("Rocket\nRun");
assert!(ident.is_err());
let ident = Ident::try_new("\tShip");
assert!(ident.is_err());
sourcepub const fn none() -> Ident
pub const fn none() -> Ident
Returns a new Ident
which is None
.
When configured as the Config::ident
, Rocket
will not set a Server
header on any response. Any Server
header
emitted by the application will still be written out.
Example
use rocket::config::Ident;
let ident = Ident::none();
assert_eq!(ident.as_str(), None);
sourcepub fn as_str(&self) -> Option<&str>
pub fn as_str(&self) -> Option<&str>
Returns self
as an Option<&str>
.
Example
use rocket::config::Ident;
let ident = Ident::try_new("Rocket").unwrap();
assert_eq!(ident.as_str(), Some("Rocket"));
let ident = Ident::try_new("Rocket/1 (Unix)").unwrap();
assert_eq!(ident.as_str(), Some("Rocket/1 (Unix)"));
let ident = Ident::none();
assert_eq!(ident.as_str(), None);