CAHash

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

Available on crate feature serde only.

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 duplicate of the value. Read more
1.0.0§

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

Available on crate feature serde only.
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

Available on crate feature daemon only.
Source§

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

Available on crate feature wire only.
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,

Available on crate feature wire only.
Source§

impl NixSerialize for CAHash

Available on crate feature daemon only.
Source§

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

Available on crate feature wire only.
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§

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

Available on crate feature serde only.
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§

§

impl<T> Any for T
where T: 'static + ?Sized,

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

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

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

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

§

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

Mutably borrows from an owned value. Read more
§

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

§

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
§

impl<T> From<T> for T

§

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
§

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

§

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
§

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

§

type Owned = T

The resulting type after obtaining ownership.
§

fn to_owned(&self) -> T

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

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

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

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

§

type Error = Infallible

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

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

Performs the conversion.
§

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

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