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§
Implementations§
source§impl CAHash
impl CAHash
pub fn hash(&self) -> Cow<'_, NixHash>
pub fn mode(&self) -> HashMode
sourcepub fn algo_str(&self) -> &'static str
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.
sourcepub fn from_nix_hex_str(s: &str) -> Option<Self>
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.
sourcepub fn to_nix_nixbase32_string(&self) -> String
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.
sourcepub(crate) fn from_map<'de, D>(
map: &Map<String, Value>,
) -> Result<Option<Self>, D::Error>where
D: Deserializer<'de>,
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<'de> Deserialize<'de> for CAHash
impl<'de> Deserialize<'de> for CAHash
source§fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
source§impl NixSerialize for CAHash
impl NixSerialize for CAHash
source§impl PartialEq for CAHash
impl PartialEq for CAHash
impl Eq for CAHash
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§default unsafe fn clone_to_uninit(&self, dst: *mut T)
default unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)