Skip to content

Commit fde6126

Browse files
committed
Asset: Add helper to get specific process flow
1 parent 0e95129 commit fde6126

1 file changed

Lines changed: 13 additions & 3 deletions

File tree

src/asset.rs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use crate::process::{Process, ProcessFlow, ProcessParameter};
55
use crate::region::RegionID;
66
use crate::time_slice::TimeSliceID;
77
use anyhow::{ensure, Context, Result};
8+
use indexmap::IndexMap;
89
use std::collections::HashSet;
910
use std::ops::RangeInclusive;
1011
use std::rc::Rc;
@@ -108,13 +109,22 @@ impl Asset {
108109
self.capacity * self.process_parameter.capacity_to_activity
109110
}
110111

111-
/// Iterate over the asset's flows
112-
pub fn iter_flows(&self) -> impl Iterator<Item = &ProcessFlow> {
112+
/// Get a specific process flow
113+
pub fn get_flow(&self, commodity_id: &CommodityID) -> Option<&ProcessFlow> {
114+
self.get_flows_map().get(commodity_id)
115+
}
116+
117+
/// Get the process flows map for this asset
118+
fn get_flows_map(&self) -> &IndexMap<CommodityID, ProcessFlow> {
113119
self.process
114120
.flows
115121
.get(&(self.region_id.clone(), self.commission_year))
116122
.unwrap()
117-
.values()
123+
}
124+
125+
/// Iterate over the asset's flows
126+
pub fn iter_flows(&self) -> impl Iterator<Item = &ProcessFlow> {
127+
self.get_flows_map().values()
118128
}
119129

120130
/// Iterate over the asset's Primary Activity Commodity flows

0 commit comments

Comments
 (0)