tame_index

Struct 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

Source§

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 u8)

🔬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.
Source§

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

Source§

type Output = T

Should always be Self
Source§

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

Source§

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>,

Source§

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>,

Source§

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
Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> MaybeSendSync for T