1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
// Copyright (C) 2020 Stephane Raux. Distributed under the MIT license.

use crate::{Block, BlockProducer, Environment};
use serde::{Deserialize, Serialize};

#[derive(Clone, Debug, Default, Deserialize, Serialize)]
pub struct Or(pub Vec<BlockProducer>);

impl Or {
    pub fn produce(&self, environment: &Environment) -> Vec<Block> {
        self.0
            .iter()
            .map(|p| p.produce(environment))
            .find(|blocks| !blocks.is_empty())
            .unwrap_or_default()
    }
}