pub struct KrateName<'name>(/* private fields */);
Expand description
Used to wrap user-provided strings so that bad crate names are required to be handled separately from things more outside the user control such as I/O errors
Implementations§
Source§impl<'name> KrateName<'name>
impl<'name> KrateName<'name>
Sourcepub fn crates_io(name: &'name str) -> Result<Self, Error>
pub fn crates_io(name: &'name str) -> Result<Self, Error>
Ensures the specified string is a valid crates.io crate name, according to the (current) crates.io name restrictions
- Non-empty
- May not start with a digit
- Maximum of 64 characters in length
- Must be ASCII alphanumeric,
-
, or_
- May not be a reserved name
- A Rust keyword
- Name of a Cargo output artifact
- Name of a std library crate (or
test
) - A reserved Windows name (such as
nul
)
Sourcepub fn cargo(name: &'name str) -> Result<Self, Error>
pub fn cargo(name: &'name str) -> Result<Self, Error>
Ensures the specified string is a valid crate name according to cargo
- Non-empty
- May not start with a digit
- Must be ASCII alphanumeric,
-
, or_
- May not be a reserved name
- A Rust keyword
- Name of a Cargo output artifact
- Name of a std library crate (or
test
) - A reserved Windows name (such as
nul
)
Source§impl<'name> KrateName<'name>
impl<'name> KrateName<'name>
Sourcepub fn prefix(&self, acc: &mut String, sep: char)
pub fn prefix(&self, acc: &mut String, sep: char)
Writes the crate’s prefix to the specified string
Cargo uses a simple prefix in the registry index so that crate’s can be partitioned, particularly on disk without running up against potential OS specific issues when hundreds of thousands of files are located with a single directory
The separator should be std::path::MAIN_SEPARATOR
in disk cases and
‘/’ when used for urls
Sourcepub fn relative_path(&self, sep: Option<char>) -> String
pub fn relative_path(&self, sep: Option<char>) -> String
Gets the relative path to a crate
This will be of the form Self::prefix
+ <sep>
+ <name>
If not specified, the separator is std::path::MAIN_SEPARATOR
let crate_name: tame_index::KrateName = "tame-index".try_into().unwrap();
assert_eq!(crate_name.relative_path(Some('/')), "ta/me/tame-index");
Trait Implementations§
Source§impl<'name> TryFrom<&'name str> for KrateName<'name>
impl<'name> TryFrom<&'name str> for KrateName<'name>
The simplest way to create a crate name, this just ensures that the crate name
is non-empty, and ASCII alphanumeric, -
, or, -
, the minimum requirements
for this crate
impl<'name> Copy for KrateName<'name>
Auto Trait Implementations§
impl<'name> Freeze for KrateName<'name>
impl<'name> RefUnwindSafe for KrateName<'name>
impl<'name> Send for KrateName<'name>
impl<'name> Sync for KrateName<'name>
impl<'name> Unpin for KrateName<'name>
impl<'name> UnwindSafe for KrateName<'name>
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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 more