pub struct CrateName(/* private fields */);Expand description
Crate name from Cargo.toml
Represents a valid Cargo crate name with validation rules:
- Non-empty
- Starts with ASCII letter (
a-z,A-Z) - Subsequent chars: ASCII alphanumeric,
-, or_ - Max 64 characters (crates.io limit)
- No reserved names
§Naming Convention
| Format | Example | Usage |
|---|---|---|
| Cargo name | ryo-mutations | [package] name in Cargo.toml |
| Module name | ryo_mutations | use ryo_mutations::... |
Use to_module_name() to convert (hyphen → underscore).
Implementations§
Source§impl CrateName
impl CrateName
Sourcepub fn new(name: impl Into<String>) -> Result<CrateName, InvalidCrateNameError>
pub fn new(name: impl Into<String>) -> Result<CrateName, InvalidCrateNameError>
Create a new CrateName with validation
§Validation Rules (Cargo naming convention)
- Non-empty
- Starts with ASCII letter (
a-z,A-Z) - Subsequent chars: ASCII alphanumeric,
-, or_ - Max 64 characters
- Not a reserved name
Sourcepub fn to_module_name(&self) -> String
pub fn to_module_name(&self) -> String
Convert to module name (hyphen → underscore)
§Example
let name = CrateName::new("ryo-mutations").unwrap();
assert_eq!(name.to_module_name(), "ryo_mutations");Sourcepub fn into_string(self) -> String
pub fn into_string(self) -> String
Consume and return the inner string
Trait Implementations§
Source§impl<'de> Deserialize<'de> for CrateName
impl<'de> Deserialize<'de> for CrateName
Source§fn deserialize<__D>(
__deserializer: __D,
) -> Result<CrateName, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<CrateName, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Source§impl Serialize for CrateName
impl Serialize for CrateName
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,
Serialize this value into the given Serde serializer. Read more
impl Eq for CrateName
impl StructuralPartialEq for CrateName
Auto Trait Implementations§
impl Freeze for CrateName
impl RefUnwindSafe for CrateName
impl Send for CrateName
impl Sync for CrateName
impl Unpin for CrateName
impl UnsafeUnpin for CrateName
impl UnwindSafe for CrateName
Blanket Implementations§
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<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> Pointable for T
impl<T> Pointable for T
Source§impl<T> ToCompactString for Twhere
T: Display,
impl<T> ToCompactString for Twhere
T: Display,
Source§fn try_to_compact_string(&self) -> Result<CompactString, ToCompactStringError>
fn try_to_compact_string(&self) -> Result<CompactString, ToCompactStringError>
Fallible version of
ToCompactString::to_compact_string() Read moreSource§fn to_compact_string(&self) -> CompactString
fn to_compact_string(&self) -> CompactString
Converts the given value to a
CompactString. Read more