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
sourceimpl 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);
Trait Implementations
sourceimpl<'de> Deserialize<'de> for Ident
impl<'de> Deserialize<'de> for Ident
sourcefn deserialize<D: Deserializer<'de>>(de: D) -> Result<Self, D::Error>
fn deserialize<D: Deserializer<'de>>(de: D) -> Result<Self, D::Error>
Deserialize this value from the given Serde deserializer. Read more
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
impl<'a, T> AsTaggedExplicit<'a> for T where
T: 'a,
impl<'a, T> AsTaggedExplicit<'a> for T where
T: 'a,
fn explicit(self, class: Class, tag: u32) -> TaggedParser<'a, Explicit, Self>
impl<'a, T> AsTaggedImplicit<'a> for T where
T: 'a,
impl<'a, T> AsTaggedImplicit<'a> for T where
T: 'a,
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> Instrument for T
impl<T> Instrument for T
sourcefn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
sourcefn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
sourceimpl<T> IntoCollection<T> for T
impl<T> IntoCollection<T> for T
sourcefn into_collection<A>(self) -> SmallVec<A> where
A: Array<Item = T>,
fn into_collection<A>(self) -> SmallVec<A> where
A: Array<Item = T>,
Converts self
into a collection.
fn mapped<U, F, A>(self, f: F) -> SmallVec<A> where
F: FnMut(T) -> U,
A: Array<Item = U>,
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcefn clone_into(&self, target: &mut T)
fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
fn vzip(self) -> V
sourceimpl<T> WithSubscriber for T
impl<T> WithSubscriber for T
sourcefn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
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
sourcefn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more