Struct ArtifactId

Source
pub struct ArtifactId<H: HashAlgorithm> { /* private fields */ }
Expand description

A universally reproducible software identifier.

This is a content-based unique identifier for any software artifact.

It is built around, per the specification, any supported hash algorithm. Currently, only SHA-256 is supported, but others may be added in the future.

Implementations§

Source§

impl<H: HashAlgorithm> ArtifactId<H>

Source

pub fn builder<P: HashProvider<H>>(provider: P) -> ArtifactIdBuilder<H, P>

Get a builder based on the chosen hash provider.

Source

pub fn try_from_url(url: Url) -> Result<ArtifactId<H>, ArtifactIdError>

Construct an ArtifactId from a gitoid-scheme Url.

This validates that the provided URL has a hashing scheme which matches the one selected for your ArtifactId (today, only sha256 is supported), and has the blob object type. It also validates that the provided hash is a valid hash for the specified hashing scheme. If any of these checks fail, the function returns an ArtifactIdError.

Note that this expects a gitoid-scheme URL, as defined by IANA. This method does not expect an HTTP or HTTPS URL to access, retrieve contents, and hash those contents to produce an identifier.

§Example
let url = Url::parse("gitoid:blob:sha256:fee53a18d32820613c0527aa79be5cb30173c823a9b448fa4817767cc84c6f03").unwrap();
let id: ArtifactId<Sha256> = ArtifactId::try_from_url(url).unwrap();
println!("Artifact ID: {}", id);
Source

pub fn try_from_safe_name(s: &str) -> Result<ArtifactId<H>, ArtifactIdError>

Try to construct an ArtifactId from a filesystem-safe representation.

Source

pub fn url(&self) -> Url

Get the Url representation of the ArtifactId.

This returns a gitoid-scheme URL for the ArtifactId.

§Example
let id: ArtifactId<Sha256> = ArtifactIdBuilder::with_rustcrypto().identify_string("hello, world");
println!("Artifact ID URL: {}", id.url());
Source

pub fn as_file_name(&self) -> PathBuf

Get a filesystem-safe representation of the ArtifactId.

This is a conservative method that tries to use only characters which can be expected to work broadly cross-platform.

What that means for us is that the : separator character is replaced with _.

Source

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

Get the underlying bytes of the ArtifactId hash.

This slice is the raw underlying buffer of the ArtifactId, exactly as produced by the hasher.

§Example
let id: ArtifactId<Sha256> = ArtifactIdBuilder::with_rustcrypto().identify_string("hello, world");
println!("Artifact ID bytes: {:?}", id.as_bytes());
Source

pub fn as_hex(&self) -> String

Get the bytes of the ArtifactId hash as a hexadecimal string.

This returns a String rather than str because the string must be constructed on the fly, as we do not store a hexadecimal representation of the hash data.

§Example
let id: ArtifactId<Sha256> = ArtifactIdBuilder::with_rustcrypto().identify_string("hello, world");
println!("Artifact ID bytes as hex: {}", id.as_hex());
Source

pub const fn hash_algorithm(&self) -> &'static str

Get the name of the hash algorithm used in the ArtifactId as a string.

For Sha256, this is the string "sha256".

§Example
let id: ArtifactId<Sha256> = ArtifactIdBuilder::with_rustcrypto().identify_string("hello, world");
println!("Artifact ID hash algorithm: {}", id.hash_algorithm());
Source

pub const fn object_type(&self) -> &'static str

Get the object type used in the ArtifactId as a string.

For all ArtifactIds this is "blob", but the method is provided for completeness nonetheless.

§Example
let id: ArtifactId<Sha256> = ArtifactIdBuilder::with_rustcrypto().identify_string("hello, world");
println!("Artifact ID object type: {}", id.object_type());
Source

pub fn hash_len(&self) -> usize

Get the length in bytes of the hash used in the ArtifactId.

In the future this method will be const, but is not able to be today due to limitations in the Rust cryptography crates we use internally.

§Example
let id: ArtifactId<Sha256> = ArtifactIdBuilder::with_rustcrypto().identify_string("hello, world");
println!("Artifact ID hash length in bytes: {}", id.hash_len());

Trait Implementations§

Source§

impl<H: HashAlgorithm> Clone for ArtifactId<H>

Source§

fn clone(&self) -> Self

Returns a duplicate 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<H: HashAlgorithm> Debug for ArtifactId<H>

Source§

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

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

impl<'de, H: HashAlgorithm> Deserialize<'de> for ArtifactId<H>

Source§

fn deserialize<D>(deserializer: D) -> StdResult<Self, D::Error>
where D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl<H: HashAlgorithm> Display for ArtifactId<H>

Source§

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

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

impl<H: HashAlgorithm> FromStr for ArtifactId<H>

Source§

type Err = ArtifactIdError

The associated error which can be returned from parsing.
Source§

fn from_str(s: &str) -> Result<ArtifactId<H>, ArtifactIdError>

Parses a string s to return a value of this type. Read more
Source§

impl<H: HashAlgorithm> Hash for ArtifactId<H>

Source§

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

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

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl<H: HashAlgorithm> Ord for ArtifactId<H>

Source§

fn cmp(&self, other: &Self) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl<H: HashAlgorithm> PartialEq for ArtifactId<H>

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · 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<H: HashAlgorithm> PartialOrd for ArtifactId<H>

Source§

fn partial_cmp(&self, other: &Self) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

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

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

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

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

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

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

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

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl<H: HashAlgorithm> Serialize for ArtifactId<H>

Source§

fn serialize<S>(&self, serializer: S) -> StdResult<S::Ok, S::Error>
where S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl<'r, H: HashAlgorithm> TryFrom<&'r str> for ArtifactId<H>

Source§

type Error = ArtifactIdError

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

fn try_from(s: &'r str) -> Result<Self, ArtifactIdError>

Performs the conversion.
Source§

impl<H: HashAlgorithm> TryFrom<Url> for ArtifactId<H>

Source§

type Error = ArtifactIdError

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

fn try_from(url: Url) -> Result<ArtifactId<H>, ArtifactIdError>

Performs the conversion.
Source§

impl<H: HashAlgorithm> Copy for ArtifactId<H>

Source§

impl<H: HashAlgorithm> Eq for ArtifactId<H>

Auto Trait Implementations§

§

impl<H> Freeze for ArtifactId<H>
where <H as HashAlgorithm>::Array: Freeze,

§

impl<H> RefUnwindSafe for ArtifactId<H>

§

impl<H> Send for ArtifactId<H>
where <H as HashAlgorithm>::Array: Send,

§

impl<H> Sync for ArtifactId<H>
where <H as HashAlgorithm>::Array: Sync,

§

impl<H> Unpin for ArtifactId<H>
where <H as HashAlgorithm>::Array: Unpin,

§

impl<H> UnwindSafe for ArtifactId<H>

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, dest: *mut u8)

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

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> 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> ToString for T
where T: Display + ?Sized,

Source§

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> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

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