Skip to content

Commit

Permalink
Remove an unnecessary wrapper for the JobSpec iterator.
Browse files Browse the repository at this point in the history
  • Loading branch information
nfachan committed Dec 13, 2024
1 parent d85b67d commit 871f9ee
Showing 1 changed file with 6 additions and 21 deletions.
27 changes: 6 additions & 21 deletions crates/maelstrom-run/src/spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,12 @@ use serde::Deserialize;
use std::collections::BTreeMap;
use std::io::Read;

struct JobSpecIterator<InnerT> {
inner: InnerT,
}

impl<InnerT> Iterator for JobSpecIterator<InnerT>
where
InnerT: Iterator<Item = serde_json::Result<Job>>,
{
type Item = Result<JobSpec>;

fn next(&mut self) -> Option<Self::Item> {
Some(match self.inner.next()? {
Err(err) => Err(err.into()),
Ok(job) => Ok(job.0),
})
}
}

pub fn job_spec_iter_from_reader(reader: impl Read) -> impl Iterator<Item = Result<JobSpec>> {
let inner = serde_json::Deserializer::from_reader(reader).into_iter::<Job>();
JobSpecIterator { inner }
pub fn job_spec_iter_from_reader(
reader: impl Read,
) -> impl Iterator<Item = serde_json::Result<JobSpec>> {
serde_json::Deserializer::from_reader(reader)
.into_iter::<Job>()
.map(|result| result.map(|job| job.0))
}

#[derive(Deserialize)]
Expand Down

0 comments on commit 871f9ee

Please sign in to comment.