Struct tame_index::KrateName

source ·
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>

source

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

  1. Non-empty
  2. May not start with a digit
  3. Maximum of 64 characters in length
  4. Must be ASCII alphanumeric, -, or _
  5. 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

pub fn cargo(name: &'name str) -> Result<Self, Error>

Ensures the specified string is a valid crate name according to cargo

  1. Non-empty
  2. May not start with a digit
  3. Must be ASCII alphanumeric, -, or _
  4. 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>

source

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

source

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> Clone for KrateName<'name>

source§

fn clone(&self) -> KrateName<'name>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<'k> Debug for KrateName<'k>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<'k> Display for KrateName<'k>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

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

§

type Error = Error

The type returned in the event of a conversion error.
source§

fn try_from(s: &'name str) -> Result<Self, Self::Error>

Performs the conversion.
source§

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> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> CloneToUninit for T
where T: Clone,

source§

unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> IntoEither for T

source§

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 more
source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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 more
source§

impl<T> Pointable for T

source§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

impl<T> Same for T

§

type Output = T

Should always be Self
source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T> ToSmolStr for T
where T: Display + ?Sized,

source§

impl<T> ToString for T
where T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more