diff options
| author | nieboczek <bartekkoraliki@gmail.com> | 2025-12-16 15:26:02 +0100 |
|---|---|---|
| committer | nieboczek <bartekkoraliki@gmail.com> | 2025-12-16 15:30:01 +0100 |
| commit | 348e44880c81f1d223f53ab11897bae427073d42 (patch) | |
| tree | 81ff7f3a167cdd5a4652f85441dc4607c317081b /server/protocol/src | |
| parent | 6419d8c8139d697af309b7db2e698effa8290582 (diff) | |
| download | hurrycurry-348e44880c81f1d223f53ab11897bae427073d42.tar hurrycurry-348e44880c81f1d223f53ab11897bae427073d42.tar.bz2 hurrycurry-348e44880c81f1d223f53ab11897bae427073d42.tar.zst | |
Return an Iterator over recipe inputs and outputs instead of a Vec
Diffstat (limited to 'server/protocol/src')
| -rw-r--r-- | server/protocol/src/helpers.rs | 28 |
1 files changed, 16 insertions, 12 deletions
diff --git a/server/protocol/src/helpers.rs b/server/protocol/src/helpers.rs index 90dfd6ff..679e6301 100644 --- a/server/protocol/src/helpers.rs +++ b/server/protocol/src/helpers.rs @@ -74,19 +74,23 @@ impl Recipe { _ => false, } } - pub fn inputs(&self) -> Vec<ItemIndex> { - match self { - Recipe::Passive { input, .. } => vec![*input], - Recipe::Active { input, .. } => vec![*input], - Recipe::Instant { inputs, .. } => inputs.iter().flat_map(|e| e.to_owned()).collect(), - } + pub fn inputs(&self) -> impl Iterator<Item = ItemIndex> { + let (a, b) = match self { + Recipe::Passive { input, .. } | Recipe::Active { input, .. } => (Some(input), None), + Recipe::Instant { inputs, .. } => (inputs[0].as_ref(), inputs[1].as_ref()), + }; + + a.into_iter().chain(b).copied() } - pub fn outputs(&self) -> Vec<ItemIndex> { - match self { - Recipe::Passive { output, .. } => output.iter().copied().collect(), - Recipe::Active { outputs, .. } => outputs.iter().flat_map(|e| e.to_owned()).collect(), - Recipe::Instant { outputs, .. } => outputs.iter().flat_map(|e| e.to_owned()).collect(), - } + pub fn outputs(&self) -> impl Iterator<Item = ItemIndex> { + let (a, b) = match self { + Recipe::Passive { output, .. } => (output, &None), + Recipe::Active { outputs, .. } | Recipe::Instant { outputs, .. } => { + (&outputs[0], &outputs[1]) + } + }; + + a.iter().chain(b.iter()).copied() } pub fn supports_tile(&self, tile: Option<TileIndex>) -> bool { if let Some(tile_constraint) = self.tile() { |