Enum nix_compat::nixhash::ca_hash::CAHash

source ·
pub enum CAHash {
    Flat(NixHash),
    Nar(NixHash),
    Text([u8; 32]),
}
Expand description

A Nix CAHash describes a content-addressed hash of a path.

The way Nix prints it as a string is a bit confusing, but there’s essentially three modes, Flat, Nar and Text. Flat and Nar support all 4 algos that NixHash supports (sha1, md5, sha256, sha512), Text only supports sha256.

Variants§

§

Flat(NixHash)

§

Nar(NixHash)

§

Text([u8; 32])

Implementations§

source§

impl CAHash

source

pub fn hash(&self) -> Cow<'_, NixHash>

source

pub fn mode(&self) -> HashMode

source

pub fn algo_str(&self) -> &'static str

Returns a colon-separated string consisting of mode, recursiveness and hash algo. Used as a prefix in various string representations.

source

pub fn from_nix_hex_str(s: &str) -> Option<Self>

Constructs a CAHash from the textual representation, which is one of the three:

  • text:sha256:$nixbase32sha256digest
  • fixed:r:$algo:$nixbase32digest
  • fixed:$algo:$nixbase32digest

These formats are used in NARInfo, for example.

source

pub fn to_nix_nixbase32_string(&self) -> String

Formats a CAHash in the Nix default hash format, which is the format that’s used in NARInfos for example.

source

pub(crate) fn from_map<'de, D>( map: &Map<String, Value>, ) -> Result<Option<Self>, D::Error>
where D: Deserializer<'de>,

This takes a serde_json::Map and turns it into this structure. This is necessary to do such shenigans because we have external consumers, like the Derivation parser, who would like to know whether we have a invalid or a missing NixHashWithMode structure in another structure, e.g. Output. This means we have this combinatorial situation:

  • no hash, no hashAlgo: no CAHash so we return Ok(None).
  • present hash, missing hashAlgo: invalid, we will return missing_field
  • missing hash, present hashAlgo: same
  • present hash, present hashAlgo: either we return ourselves or a type/value validation error.

This function is for internal consumption regarding those needs until we have a better solution. Now this is said, let’s explain how this works.

We want to map the serde data model into a CAHash.

The serde data model has a hash field (containing a digest in nixbase32), and a hashAlgo field, containing the stringified hash algo. In case the hash is recursive, hashAlgo also has a r: prefix.

This is to match how nix show-derivation command shows them in JSON representation.

Trait Implementations§

source§

impl Clone for CAHash

source§

fn clone(&self) -> CAHash

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 Debug for CAHash

source§

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

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

impl<'de> Deserialize<'de> for CAHash

source§

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

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

impl NixDeserialize for CAHash

source§

async fn try_deserialize<R>(reader: &mut R) -> Result<Option<Self>, R::Error>
where R: ?Sized + NixRead + Send,

Read a value from the reader. This returns an Option to support gracefull shutdown.
source§

fn deserialize<R>( reader: &mut R, ) -> impl Future<Output = Result<Self, R::Error>> + Send + '_
where R: ?Sized + NixRead + Send,

source§

impl NixSerialize for CAHash

source§

async fn serialize<W>(&self, writer: &mut W) -> Result<(), W::Error>
where W: NixWrite,

Write a value to the writer.
source§

impl PartialEq for CAHash

source§

fn eq(&self, other: &CAHash) -> 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 Serialize for CAHash

source§

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

map a CAHash into the serde data model.

source§

impl Eq for CAHash

source§

impl StructuralPartialEq for CAHash

Auto Trait Implementations§

§

impl Freeze for CAHash

§

impl RefUnwindSafe for CAHash

§

impl Send for CAHash

§

impl Sync for CAHash

§

impl Unpin for CAHash

§

impl UnwindSafe for CAHash

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