pub struct DomainName(/* private fields */);Expand description
A validated domain name
This type guarantees that the contained string passes basic domain name
validation (see module docs for validation rules). It’s immutable and
provides access to the underlying string via as_str().
§Construction
Use DomainName::new() to create a validated instance. The constructor
validates the input and returns a Result with a detailed error if
validation fails.
§Serialization
Implements Serde traits with validation on deserialization. Invalid domain names will cause deserialization to fail with a descriptive error.
Implementations§
Source§impl DomainName
impl DomainName
Sourcepub fn new(domain: &str) -> Result<DomainName, DomainNameError>
pub fn new(domain: &str) -> Result<DomainName, DomainNameError>
Creates a new validated domain name
§Arguments
domain- A string slice containing the domain name to validate
§Errors
Returns DomainNameError if the domain name is invalid:
EmptyDomain- Domain is emptyInvalidFormat- Domain has typos or formatting issues
§Examples
use torrust_tracker_deployer_types::DomainName;
let domain = DomainName::new("tracker.torrust.org").unwrap();
assert_eq!(domain.as_str(), "tracker.torrust.org");Sourcepub fn tld(&self) -> &str
pub fn tld(&self) -> &str
Extracts the top-level domain (TLD)
§Panics
This method will not panic because DomainName is validated at
construction to always contain at least one dot (TLD separator).
§Examples
use torrust_tracker_deployer_types::DomainName;
let domain = DomainName::new("api.tracker.torrust.org").unwrap();
assert_eq!(domain.tld(), "org");Sourcepub fn subdomains(&self) -> Vec<&str>
pub fn subdomains(&self) -> Vec<&str>
Returns all subdomains as a vector (excluding TLD)
§Examples
use torrust_tracker_deployer_types::DomainName;
let domain = DomainName::new("api.tracker.torrust.org").unwrap();
assert_eq!(domain.subdomains(), vec!["api", "tracker", "torrust"]);Trait Implementations§
Source§impl AsRef<str> for DomainName
impl AsRef<str> for DomainName
Source§impl Clone for DomainName
impl Clone for DomainName
Source§fn clone(&self) -> DomainName
fn clone(&self) -> DomainName
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for DomainName
impl Debug for DomainName
Source§impl<'de> Deserialize<'de> for DomainName
impl<'de> Deserialize<'de> for DomainName
Source§fn deserialize<D>(
deserializer: D,
) -> Result<DomainName, <D as Deserializer<'de>>::Error>where
D: Deserializer<'de>,
fn deserialize<D>(
deserializer: D,
) -> Result<DomainName, <D as Deserializer<'de>>::Error>where
D: Deserializer<'de>,
Source§impl Display for DomainName
impl Display for DomainName
impl Eq for DomainName
Source§impl From<DomainName> for String
impl From<DomainName> for String
Source§fn from(domain: DomainName) -> String
fn from(domain: DomainName) -> String
Source§impl Hash for DomainName
impl Hash for DomainName
Source§impl JsonSchema for DomainName
impl JsonSchema for DomainName
Source§fn schema_id() -> Cow<'static, str>
fn schema_id() -> Cow<'static, str>
Source§fn json_schema(generator: &mut SchemaGenerator) -> Schema
fn json_schema(generator: &mut SchemaGenerator) -> Schema
Source§fn inline_schema() -> bool
fn inline_schema() -> bool
$ref keyword. Read moreSource§impl PartialEq for DomainName
impl PartialEq for DomainName
Source§impl Serialize for DomainName
impl Serialize for DomainName
Source§fn serialize<S>(
&self,
serializer: S,
) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>where
S: Serializer,
fn serialize<S>(
&self,
serializer: S,
) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>where
S: Serializer,
impl StructuralPartialEq for DomainName
Source§impl TryFrom<String> for DomainName
impl TryFrom<String> for DomainName
Source§type Error = DomainNameError
type Error = DomainNameError
Source§fn try_from(
value: String,
) -> Result<DomainName, <DomainName as TryFrom<String>>::Error>
fn try_from( value: String, ) -> Result<DomainName, <DomainName as TryFrom<String>>::Error>
Auto Trait Implementations§
impl Freeze for DomainName
impl RefUnwindSafe for DomainName
impl Send for DomainName
impl Sync for DomainName
impl Unpin for DomainName
impl UnsafeUnpin for DomainName
impl UnwindSafe for DomainName
Blanket Implementations§
Source§impl<T> AsUncased for T
impl<T> AsUncased for T
Source§fn as_uncased(&self) -> &UncasedStr
fn as_uncased(&self) -> &UncasedStr
self to an UncasedStr.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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.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> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::RequestSource§impl<I> IntoResettable<String> for I
impl<I> IntoResettable<String> for I
Source§fn into_resettable(self) -> Resettable<String>
fn into_resettable(self) -> Resettable<String>
Source§impl<T> IntoResult<T> for T
impl<T> IntoResult<T> for T
type Err = !
fn into_result(self) -> Result<T, <T as IntoResult<T>>::Err>
Source§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<T> ToStringFallible for Twhere
T: Display,
impl<T> ToStringFallible for Twhere
T: Display,
Source§fn try_to_string(&self) -> Result<String, TryReserveError>
fn try_to_string(&self) -> Result<String, TryReserveError>
ToString::to_string, but without panic on OOM.