Struct rocket::config::Ident

source ·
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§

source§

impl Ident

source

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

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

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

Trait Implementations§

source§

impl Clone for Ident

source§

fn clone(&self) -> Ident

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 Ident

source§

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

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

impl Default for Ident

The default Ident is "Rocket".

source§

fn default() -> Self

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

impl<'de> Deserialize<'de> for Ident

source§

fn deserialize<D: Deserializer<'de>>(de: D) -> Result<Self, D::Error>

Deserialize this value from the given Serde deserializer. Read more
source§

impl Display for Ident

source§

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

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

impl PartialEq<Ident> for Ident

source§

fn eq(&self, other: &Ident) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Serialize for Ident

source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
source§

impl StructuralPartialEq for Ident

Auto Trait Implementations§

§

impl RefUnwindSafe for Ident

§

impl Send for Ident

§

impl Sync for Ident

§

impl Unpin for Ident

§

impl UnwindSafe for Ident

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.

source§

impl<T> IntoCollection<T> for T

source§

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

Converts self into a collection.
source§

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> ToString for Twhere T: Display + ?Sized,

source§

default fn to_string(&self) -> String

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

impl<T> DeserializeOwned for Twhere T: for<'de> Deserialize<'de>,