Skip to main content

StorePathName

Struct StorePathName 

Source
#[repr(transparent)]
pub struct StorePathName(str);
Expand description

Validated name of a store path.

The name may only contain ASCII alphanumeric, or one of the following characters: -, _, ., +, ?, = and must be shorter than 211 characters long.

Tuple Fields§

§0: str

Implementations§

Source§

impl StorePathName

Source

pub const fn max_len() -> usize

Maximum number of bytes in a store path name.

Source

pub const fn source() -> &'static StorePathName

Return default name of sources.

§Examples
assert_eq!(StorePathName::source(), "source");
Source

pub const unsafe fn from_str_unchecked(name: &str) -> &StorePathName

Converts a str to a StorePathName without checking that it is a valid name.

§Safety

This function is unsafe because it does not check that the str passed to it is a valid store path name. If this constraint is violated it may cause panics and memory safety issues , as the rest of snix assumes that StorePathName contains a valid store path name.

Source

pub fn from_str(name: &str) -> Result<&StorePathName, ParseStorePathNameError>

Checks a given &str to match the restrictions for StorePathName, and returns the name as &StorePathName if successful.

Source

pub fn from_slice( name: &[u8], ) -> Result<&StorePathName, ParseStorePathNameError>

Checks a given &[u8] to match the restrictions for StorePathName, and returns the name as &StorePathName if successful.

Source

pub fn from_os_str( name: &OsStr, ) -> Result<&StorePathName, ParseStorePathNameError>

Checks a given OsStr to match the restrictions for StorePathName, and returns the name as &StorePathName if successful

Source

pub fn build_drv_name( &self, ) -> Result<StorePathNameBuf, ParseStorePathNameError>

Build a new StorePathNameBuf by adding .drv extension to this StorePathName. This fails if this name already ends in .drv or the resulting name would be too long.

§Examples
let n = StorePathName::from_str("snix-eval").unwrap();
assert_eq!(n.build_drv_name().unwrap(), "snix-eval.drv");
Source

pub fn is_drv(&self) -> bool

Returns true if this is the name of a derivation.

Derivation names always end in .drv and has len() longer than 4.

§Examples
let n = StorePathName::from_str("snix-eval").unwrap();
assert!(!n.is_drv());

let b = n.build_drv_name().unwrap();
assert!(b.is_drv());
Source

pub fn strip_drv_ext(&self) -> Option<&StorePathName>

Remove .drv extension from this name or return None if this is not a derivation name.

Source

pub fn strip_suffix(&self, suffix: &str) -> Option<&StorePathName>

Strip a suffix from this name or return None if the resulting name would have been empty.

Source

pub const fn len(&self) -> usize

Returns the length of this name.

§Examples
assert_eq!(6, StorePathName::source().len());
Source

pub const fn as_str(&self) -> &str

Converts a name to a string. To convert the string back into a name, use the Self::from_str function.

§Examples
let s = StorePathName::source().as_str();
assert_eq!("source", s);
Source

pub const fn as_bytes(&self) -> &[u8] ⓘ

Converts a name to a byte slice. To convert the byte slice back into a name, use the Self::from_slice function.

§Examples
let bytes = StorePathName::source().as_bytes();
assert_eq!(b"source", bytes);

Trait Implementations§

Source§

impl AsRef<[u8]> for StorePathName

Source§

fn as_ref(&self) -> &[u8] ⓘ

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl AsRef<StorePathName> for StorePathName

Source§

fn as_ref(&self) -> &StorePathName

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl AsRef<StorePathName> for StorePathNameBuf

Source§

fn as_ref(&self) -> &StorePathName

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl AsRef<str> for StorePathName

Source§

fn as_ref(&self) -> &str

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl Borrow<StorePathName> for StorePathNameBuf

Source§

fn borrow(&self) -> &StorePathName

Immutably borrows from an owned value. Read more
Source§

impl Debug for StorePathName

Source§

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

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

impl Display for StorePathName

Source§

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

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

impl<'a> From<&'a StorePathName> for StorePathNameBuf

Source§

fn from(value: &'a StorePathName) -> Self

Converts to this type from the input type.
Source§

impl Hash for StorePathName

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
Source§

impl PartialEq<&StorePathName> for StorePathNameBuf

Source§

fn eq(&self, other: &&StorePathName) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialEq<&str> for StorePathName

Source§

fn eq(&self, other: &&str) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialEq<StorePathName> for &str

Source§

fn eq(&self, other: &StorePathName) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialEq<StorePathName> for String

Source§

fn eq(&self, other: &StorePathName) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialEq<StorePathName> for str

Source§

fn eq(&self, other: &StorePathName) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialEq<StorePathNameBuf> for &StorePathName

Source§

fn eq(&self, other: &StorePathNameBuf) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialEq<String> for StorePathName

Source§

fn eq(&self, other: &String) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialEq<str> for StorePathName

Source§

fn eq(&self, other: &str) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialEq for StorePathName

Source§

fn eq(&self, other: &StorePathName) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl ToOwned for StorePathName

Source§

type Owned = StorePathNameBuf

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> Self::Owned

Creates owned data from borrowed data, usually by cloning. Read more
1.63.0 · Source§

fn clone_into(&self, target: &mut Self::Owned)

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

impl<'a> TryFrom<&'a [u8]> for &'a StorePathName

Source§

type Error = ParseStorePathNameError

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

fn try_from(name: &'a [u8]) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl<'a> TryFrom<&'a str> for &'a StorePathName

Source§

type Error = ParseStorePathNameError

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

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

Performs the conversion.
Source§

impl Eq for StorePathName

Source§

impl StructuralPartialEq for StorePathName

Auto Trait Implementations§

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<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

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

Source§

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

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more