diff options
author | Daniel Schadt <kingdread@gmx.de> | 2020-10-23 15:09:43 +0200 |
---|---|---|
committer | Daniel Schadt <kingdread@gmx.de> | 2020-10-23 15:09:43 +0200 |
commit | 6c7e6c73a7bafe4ee90e145e4c067f4658e9a827 (patch) | |
tree | 62483cf27b6ee8949fb034ba29c1948a4a9c8330 /src | |
parent | b1b3fe58eb18520c5ce86c2938fb3dc2ac292f23 (diff) | |
download | evtclib-6c7e6c73a7bafe4ee90e145e4c067f4658e9a827.tar.gz evtclib-6c7e6c73a7bafe4ee90e145e4c067f4658e9a827.tar.bz2 evtclib-6c7e6c73a7bafe4ee90e145e4c067f4658e9a827.zip |
use iterator methods instead of for loops
No particular reason other than it's more idiomatic and shorter.
inline has been added to get_agent_by_addr since it "feels" like a short
function that can and should be inlined, but it doesn't matter too much.
Diffstat (limited to 'src')
-rw-r--r-- | src/processing.rs | 15 |
1 files changed, 3 insertions, 12 deletions
diff --git a/src/processing.rs b/src/processing.rs index 11bdda7..3f72b39 100644 --- a/src/processing.rs +++ b/src/processing.rs @@ -100,21 +100,12 @@ pub fn process_file<P: AsRef<Path>>(path: P, compression: Compression) -> Result } fn setup_agents(data: &raw::Evtc) -> Result<Vec<Agent>, EvtcError> { - let mut agents = Vec::with_capacity(data.agents.len()); - - for raw_agent in &data.agents { - agents.push(Agent::try_from(raw_agent)?); - } - Ok(agents) + data.agents.iter().map(Agent::try_from).collect() } +#[inline] fn get_agent_by_addr(agents: &mut [Agent], addr: u64) -> Option<&mut Agent> { - for agent in agents { - if agent.addr() == addr { - return Some(agent); - } - } - None + agents.iter_mut().find(|agent| agent.addr() == addr) } fn set_agent_awares(data: &raw::Evtc, agents: &mut [Agent]) -> Result<(), EvtcError> { |