Skip to content

Commit c6c65e0

Browse files
committed
get_id: Don't clone ID on return
1 parent f240b97 commit c6c65e0

7 files changed

Lines changed: 16 additions & 12 deletions

File tree

src/id.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,16 +84,16 @@ pub trait IDCollection<ID: IDLike> {
8484
/// # Returns
8585
///
8686
/// A copy of the ID in `self`, or an error if not found.
87-
fn get_id<T: Borrow<str> + Display + ?Sized>(&self, id: &T) -> Result<ID>;
87+
fn get_id<T: Borrow<str> + Display + ?Sized>(&self, id: &T) -> Result<&ID>;
8888
}
8989

9090
macro_rules! define_id_methods {
9191
() => {
92-
fn get_id<T: Borrow<str> + Display + ?Sized>(&self, id: &T) -> Result<ID> {
92+
fn get_id<T: Borrow<str> + Display + ?Sized>(&self, id: &T) -> Result<&ID> {
9393
let found = self
9494
.get(id.borrow())
9595
.with_context(|| format!("Unknown ID {id} found"))?;
96-
Ok(found.clone())
96+
Ok(found)
9797
}
9898
};
9999
}

src/input/agent/search_space.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ impl AgentSearchSpaceRaw {
6363

6464
Ok(AgentSearchSpace {
6565
agent_id: agent_id.clone(),
66-
commodity_id,
66+
commodity_id: commodity_id.clone(),
6767
years: year,
6868
search_space,
6969
})
@@ -86,7 +86,7 @@ fn parse_search_space_str(
8686
} else {
8787
search_space
8888
.split(';')
89-
.map(|id| process_ids.get_id(id.trim()))
89+
.map(|id| Ok(process_ids.get_id(id.trim())?.clone()))
9090
.try_collect()
9191
}
9292
}

src/input/asset.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,9 @@ where
7676
let region_id = region_ids.get_id(&asset.region_id)?;
7777

7878
Asset::new(
79-
agent_id,
79+
agent_id.clone(),
8080
Rc::clone(process),
81-
region_id,
81+
region_id.clone(),
8282
asset.capacity,
8383
asset.commission_year,
8484
)

src/input/process/availability.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ where
111111
// Get process
112112
let id = process_ids.get_id(&record.process_id)?;
113113
let process = processes
114-
.get(&id)
114+
.get(id)
115115
.with_context(|| format!("Process {id} not found"))?;
116116

117117
// Get regions
@@ -131,7 +131,9 @@ where
131131
let ts_selection = time_slice_info.get_selection(&record.time_slice)?;
132132

133133
// Insert the energy limit into the map
134-
let entry = map.entry(id).or_insert_with(ProcessEnergyLimitsMap::new);
134+
let entry = map
135+
.entry(id.clone())
136+
.or_insert_with(ProcessEnergyLimitsMap::new);
135137
for (time_slice, ts_length) in time_slice_info.iter_selection(&ts_selection) {
136138
let bounds = record.to_bounds(ts_length);
137139

src/input/process/flow.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ where
8484
// Get process
8585
let id = process_ids.get_id(&record.process_id)?;
8686
let process = processes
87-
.get(&id)
87+
.get(id)
8888
.with_context(|| format!("Process {id} not found"))?;
8989

9090
// Get regions

src/input/process/parameter.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ where
119119
// Get process
120120
let id = process_ids.get_id(&param_raw.process_id)?;
121121
let process = processes
122-
.get(&id)
122+
.get(id)
123123
.with_context(|| format!("Process {id} not found"))?;
124124

125125
// Get years

src/region.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@ pub fn parse_region_str(s: &str, region_ids: &HashSet<RegionID>) -> Result<HashS
3232
return Ok(region_ids.clone());
3333
}
3434

35-
s.split(";").map(|y| region_ids.get_id(y.trim())).collect()
35+
s.split(";")
36+
.map(|y| Ok(region_ids.get_id(y.trim())?.clone()))
37+
.collect()
3638
}
3739

3840
#[cfg(test)]

0 commit comments

Comments
 (0)