foundry_compilers/compile/
many.rs

1use foundry_compilers_artifacts::{CompilerOutput, SolcInput};
2use foundry_compilers_core::error::Result;
3
4use crate::compilers::solc::Solc;
5
6/// The result of a `solc` process bundled with its `Solc` and `CompilerInput`
7type CompileElement = (Result<CompilerOutput>, Solc, SolcInput);
8
9/// The bundled output of multiple `solc` processes.
10#[derive(Debug)]
11pub struct CompiledMany {
12    outputs: Vec<CompileElement>,
13}
14
15impl CompiledMany {
16    pub fn new(outputs: Vec<CompileElement>) -> Self {
17        Self { outputs }
18    }
19
20    /// Returns an iterator over all output elements
21    pub fn outputs(&self) -> impl Iterator<Item = &CompileElement> {
22        self.outputs.iter()
23    }
24
25    /// Returns an iterator over all output elements
26    pub fn into_outputs(self) -> impl Iterator<Item = CompileElement> {
27        self.outputs.into_iter()
28    }
29
30    /// Returns all `CompilerOutput` or the first error that occurred
31    pub fn flattened(self) -> Result<Vec<CompilerOutput>> {
32        self.into_iter().collect()
33    }
34}
35
36impl IntoIterator for CompiledMany {
37    type Item = Result<CompilerOutput>;
38    type IntoIter = std::vec::IntoIter<Result<CompilerOutput>>;
39
40    fn into_iter(self) -> Self::IntoIter {
41        self.outputs.into_iter().map(|(res, _, _)| res).collect::<Vec<_>>().into_iter()
42    }
43}