pub struct Outputs(OutputsInner);Expand description
Derivation outputs.
Outputs are generally mappings from OutputName to a Output but
with some extra invariants.
§Invariants
- If there is only one output it is named
out - Only a single FOD output is allowed
- Duplicately named outputs is an error
- Outputs can not be empty
§StorePath for an Output
When a derivation is being constructed the StorePath of each output
is not known yet and so Outputs does support this.
But generally you should call calculate_output_paths and after that
the StorePath of each output is available and will never change.
It is for this reason that the only method mutating Outputs after
construction is calculate_output_paths.
Tuple Fields§
§0: OutputsInnerImplementations§
Source§impl Outputs
impl Outputs
Sourcepub const fn from_fod_hash(output_hash: OutputHash) -> Self
pub const fn from_fod_hash(output_hash: OutputHash) -> Self
Return Ouputs with single fixed-output that matches output_hash.
§Examples
use nix_compat::derivation::{Outputs, OutputName};
let b = Outputs::from_fod_hash(output_hash);
assert!(b.is_single());
assert!(b.is_fixed());
assert!(b.contains_key(&OutputName::out()));Sourcepub const fn with_single_output() -> Self
pub const fn with_single_output() -> Self
Return a new Ouputs with just a single output.
That single output is always called out.
§Examples
use nix_compat::derivation::{Outputs, OutputName};
let b = Outputs::with_single_output();
assert!(b.is_single());
assert!(b.contains_key(&OutputName::out()));Sourcepub fn try_from_iter<I>(it: I) -> Result<Self, OutputsError>
pub fn try_from_iter<I>(it: I) -> Result<Self, OutputsError>
Try to make Outputs from the provided iterator.
This will return a OutputsError if the OutputName, Output pairs
in the iterator don’t follow the invariants.
Sourcepub fn contains_key(&self, name: &OutputName) -> bool
pub fn contains_key(&self, name: &OutputName) -> bool
Returns true if the outputs contains an output with the specified name.
Sourcepub fn get(&self, name: &OutputName) -> Option<&Output>
pub fn get(&self, name: &OutputName) -> Option<&Output>
Returns a reference to the Output corresponding to the provided name.
Sourcepub fn iter(&self) -> Iter<'_> ⓘ
pub fn iter(&self) -> Iter<'_> ⓘ
Gets an iterator over the entries of the outputs, sorted by name.
Sourcepub fn keys(&self) -> impl Iterator<Item = &OutputName>
pub fn keys(&self) -> impl Iterator<Item = &OutputName>
Gets an iterator over the names of the outputs, in sorted order.
§Examples
use nix_compat::derivation::{Outputs, OutputName};
let a = Outputs::try_from_iter([
(OutputName::out(), Default::default()),
(OutputName::from_static("bin").unwrap(), Default::default()),
]).expect("multiple outputs");
let keys: Vec<OutputName> = a.keys().cloned().collect();
assert_eq!(keys, [
OutputName::from_static("bin").unwrap(),
OutputName::out(),
]);Sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
Returns the number of outputs
§Examples
use nix_compat::derivation::{Outputs, OutputName};
let a = Outputs::with_single_output();
assert_eq!(a.len(), 1);
let b = Outputs::try_from_iter([
(OutputName::out(), Default::default()),
(OutputName::from_static("bin").unwrap(), Default::default()),
]).expect("multiple outputs");
assert_eq!(b.len(), 2);Sourcepub fn is_single(&self) -> bool
pub fn is_single(&self) -> bool
Returns true if this contains only a single output.
§Examples
use nix_compat::derivation::{Outputs, OutputName};
let a = Outputs::with_single_output();
assert!(a.is_single());
let b = Outputs::from_fod_hash(output_hash);
assert!(b.is_single());
let c = Outputs::try_from_iter([
(OutputName::out(), Default::default()),
(OutputName::from_static("bin").unwrap(), Default::default()),
]).unwrap();
assert!(!c.is_single());Sourcepub fn calculate_output_paths(
&mut self,
drv_name: &str,
hash_derivation_modulo: &[u8; 32],
) -> Result<(), OutputsError>
pub fn calculate_output_paths( &mut self, drv_name: &str, hash_derivation_modulo: &[u8; 32], ) -> Result<(), OutputsError>
This calculates all output paths of a Outputs and updates the struct.
It requires the struct to be initially without output paths.
This means, Output::path needs to be None for each output.
Output path calculation requires knowledge of the
hash_derivation_modulo, which (in case of non-fixed-output
derivations) also requires knowledge of the
hash_derivation_modulo of input derivations (recursively).
To avoid recursing and doing unnecessary calculation, we simply
ask the caller of this function to provide the result of the
hash_derivation_modulo call of the current Derivation,
and leave it up to them to calculate it when needed.
On completion, Output::path of each output is set to the calculated output path.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Outputs
Available on crate feature serde only.
impl<'de> Deserialize<'de> for Outputs
serde only.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<'a> IntoIterator for &'a Outputs
impl<'a> IntoIterator for &'a Outputs
impl Eq for Outputs
impl StructuralPartialEq for Outputs
Auto Trait Implementations§
impl Freeze for Outputs
impl RefUnwindSafe for Outputs
impl Send for Outputs
impl Sync for Outputs
impl Unpin for Outputs
impl UnsafeUnpin for Outputs
impl UnwindSafe for Outputs
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§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.