ethers_solc/compile/
many.rs

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