pub struct InstanceName(/* private fields */);Expand description
A validated instance name following LXD naming requirements.
This type ensures that names are valid for both LXD virtual machines used in production deployments and Docker containers used in end-to-end testing.
Valid instance 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 instance name can be used in DNS records, on the file system, in various security profiles and as the host name.
§Use Cases
- LXD Virtual Machines: Naming VMs provisioned for deployment environments
- Testing Containers: Naming Docker containers in E2E test scenarios
§Examples
use torrust_tracker_deployer_lib::domain::InstanceName;
// Valid instance names - accepts both &str and String
let vm_instance = InstanceName::new("torrust-vm-prod")?;
let test_container = InstanceName::new("test-container-01".to_string())?;
let dynamic_name = InstanceName::new(format!("app-{}", "staging"))?;
// Invalid instance names
assert!(InstanceName::new("").is_err());
assert!(InstanceName::new("test-").is_err());
assert!(InstanceName::new("-test").is_err());
assert!(InstanceName::new("1test").is_err());Implementations§
Source§impl InstanceName
impl InstanceName
Sourcepub fn new<S: Into<String>>(name: S) -> Result<Self, InstanceNameError>
pub fn new<S: Into<String>>(name: S) -> Result<Self, InstanceNameError>
Creates a new InstanceName from a string if it’s valid.
This method validates that the provided name meets the requirements for both LXD virtual machines and testing containers.
§Arguments
name- The instance name to validate (accepts&str,String, or anything that implementsInto<String>)
§Returns
Ok(InstanceName)- If the name is validErr(InstanceNameError)- 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::InstanceName;
// Valid names for VMs and containers - accepts both &str and String
let vm_name = InstanceName::new("torrust-vm-prod")?;
let container_name = InstanceName::new("test-web-01".to_string())?;
let dynamic_name = InstanceName::new(format!("app-{}", "staging"))?;
// Invalid names
assert!(InstanceName::new("").is_err());
assert!(InstanceName::new("test-").is_err());
assert!(InstanceName::new("-test").is_err());
assert!(InstanceName::new("1test").is_err());Trait Implementations§
Source§impl AsRef<str> for InstanceName
impl AsRef<str> for InstanceName
Source§impl Clone for InstanceName
impl Clone for InstanceName
Source§fn clone(&self) -> InstanceName
fn clone(&self) -> InstanceName
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for InstanceName
impl Debug for InstanceName
Source§impl<'de> Deserialize<'de> for InstanceName
impl<'de> Deserialize<'de> for InstanceName
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 InstanceName
impl Display for InstanceName
Source§impl FromStr for InstanceName
impl FromStr for InstanceName
Source§impl Hash for InstanceName
impl Hash for InstanceName
Source§impl PartialEq for InstanceName
impl PartialEq for InstanceName
Source§impl Serialize for InstanceName
impl Serialize for InstanceName
Source§impl TryFrom<String> for InstanceName
impl TryFrom<String> for InstanceName
Source§type Error = InstanceNameError
type Error = InstanceNameError
The type returned in the event of a conversion error.
impl Eq for InstanceName
impl StructuralPartialEq for InstanceName
Auto Trait Implementations§
impl Freeze for InstanceName
impl RefUnwindSafe for InstanceName
impl Send for InstanceName
impl Sync for InstanceName
impl Unpin for InstanceName
impl UnsafeUnpin for InstanceName
impl UnwindSafe for InstanceName
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,
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<T> IntoResult<T> for T
impl<T> IntoResult<T> for T
type Err = Infallible
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.