Skip to main content

Outputs

Struct Outputs 

Source
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: OutputsInner

Implementations§

Source§

impl Outputs

Source

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()));
Source

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()));
Source

pub fn try_from_iter<I>(it: I) -> Result<Self, OutputsError>
where I: IntoIterator<Item = (OutputName, Output)>,

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.

Source

pub fn contains_key(&self, name: &OutputName) -> bool

Returns true if the outputs contains an output with the specified name.

Source

pub fn get(&self, name: &OutputName) -> Option<&Output>

Returns a reference to the Output corresponding to the provided name.

Source

pub fn iter(&self) -> Iter<'_>

Gets an iterator over the entries of the outputs, sorted by name.

Source

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(),
]);
Source

pub fn values(&self) -> impl Iterator<Item = &Output>

Gets an iterator over the Output values of the outputs, in order by name.

§Examples
use nix_compat::derivation::{Output, Outputs, OutputName};

let a = Outputs::with_single_output();

let values: Vec<Output> = a.values().cloned().collect();
assert_eq!(values, [Output::default()]);
Source

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);
Source

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());
Source

pub fn is_fixed(&self) -> bool

Returns true if this is a single fixed-output.

Source

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 Clone for Outputs

Source§

fn clone(&self) -> Outputs

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Outputs

Source§

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

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

impl Default for Outputs

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for Outputs

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<'a> IntoIterator for &'a Outputs

Source§

type Item = (&'a OutputName, &'a Output)

The type of the elements being iterated over.
Source§

type IntoIter = Iter<'a>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl PartialEq for Outputs

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · 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 Outputs

Available on crate feature serde only.
Source§

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

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

impl TryFrom<BTreeMap<OutputName, Output>> for Outputs

Source§

type Error = OutputsError

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

fn try_from(outputs: BTreeMap<OutputName, Output>) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl Eq for Outputs

Source§

impl StructuralPartialEq for Outputs

Auto Trait Implementations§

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<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
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>,