logo
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. See Ident::try_new() for details.

  • boolean

    The boolean must be false. The value will be Ident::none().

  • Option<string>

    If Some, this is the same as deserializing from the inner string. If None, the value is Ident::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

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());

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

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

Trait Implementations

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 Ident is "Rocket".

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

Deserialize this value from the given Serde deserializer. Read more

Formats the value using the given formatter. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

Serialize this value into the given Serde serializer. 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

Converts the given value to a String. 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