pub struct ProfileName(/* private fields */);Expand description
A validated LXD profile name following LXD naming requirements.
Valid profile names must fulfill the following requirements:
- The name must be between 1 and 63 characters long
- The name must contain only letters, numbers and dashes from the ASCII table
- The name must not start with a digit or a dash
- The name must not end with a dash
These requirements ensure that the profile name can be used in DNS records, on the file system, in various security profiles and as the host name.
§Examples
use torrust_tracker_deployer_lib::domain::ProfileName;
// Valid profile names - accepts both &str and String
let profile1 = ProfileName::new("test-profile")?;
let profile2 = ProfileName::new("web-server-profile".to_string())?;
let profile3 = ProfileName::new(format!("app-{}-profile", "prod"))?;
// Invalid profile names
assert!(ProfileName::new("").is_err());
assert!(ProfileName::new("test-").is_err());
assert!(ProfileName::new("-test").is_err());
assert!(ProfileName::new("1test").is_err());Implementations§
Source§impl ProfileName
impl ProfileName
Sourcepub fn new<S: Into<String>>(name: S) -> Result<Self, ProfileNameError>
pub fn new<S: Into<String>>(name: S) -> Result<Self, ProfileNameError>
Creates a new ProfileName from a string if it’s valid.
§Arguments
name- The profile name to validate (accepts&str,String, or anything that implementsInto<String>)
§Returns
Ok(ProfileName)- If the name is validErr(ProfileNameError)- If the name violates LXD naming requirements
§Errors
This function will return an error if the name violates any LXD naming requirements:
- Empty name
- Name longer than 63 characters
- Name contains non-ASCII letters, numbers, or dashes
- Name starts with a digit or dash
- Name ends with a dash
§Examples
use torrust_tracker_deployer_lib::domain::ProfileName;
// Valid names - accepts both &str and String
let name1 = ProfileName::new("test-profile")?;
let name2 = ProfileName::new("web-01-profile".to_string())?;
let name3 = ProfileName::new(format!("app-{}-profile", "prod"))?;
// Invalid names
assert!(ProfileName::new("").is_err());
assert!(ProfileName::new("test-").is_err());
assert!(ProfileName::new("-test").is_err());
assert!(ProfileName::new("1test").is_err());Trait Implementations§
Source§impl AsRef<str> for ProfileName
impl AsRef<str> for ProfileName
Source§impl Clone for ProfileName
impl Clone for ProfileName
Source§impl Debug for ProfileName
impl Debug for ProfileName
Source§impl<'de> Deserialize<'de> for ProfileName
impl<'de> Deserialize<'de> for ProfileName
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Source§impl Display for ProfileName
impl Display for ProfileName
impl Eq for ProfileName
Source§impl From<ProfileName> for String
impl From<ProfileName> for String
Source§fn from(profile_name: ProfileName) -> Self
fn from(profile_name: ProfileName) -> Self
Converts to this type from the input type.
Source§impl FromStr for ProfileName
impl FromStr for ProfileName
Source§impl Hash for ProfileName
impl Hash for ProfileName
Source§impl PartialEq for ProfileName
impl PartialEq for ProfileName
Source§impl Serialize for ProfileName
impl Serialize for ProfileName
impl StructuralPartialEq for ProfileName
Auto Trait Implementations§
impl Freeze for ProfileName
impl RefUnwindSafe for ProfileName
impl Send for ProfileName
impl Sync for ProfileName
impl Unpin for ProfileName
impl UnsafeUnpin for ProfileName
impl UnwindSafe for ProfileName
Blanket Implementations§
Source§impl<T> AsUncased for T
impl<T> AsUncased for T
Source§fn as_uncased(&self) -> &UncasedStr
fn as_uncased(&self) -> &UncasedStr
Convert
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
Mutably borrows from an owned value. Read more
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
Compare self to
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> ⓘ
Converts
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> ⓘ
Converts
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>
Wrap the input message
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>
Convert to the intended resettable type
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.