| |
pub fn get(&self, id: &JobId) -> Result<Option<Job>, store::Error> {
|
| |
self.raw.get(id.as_object_id())
|
| |
}
|
| + |
|
| + |
/// Find the [`Job`]s that are associated with the `wanted` commit.
|
| + |
pub fn find_by_commit(&self, wanted: Oid) -> Result<FindByCommit<'a>, store::Error> {
|
| + |
FindByCommit::new(self, wanted)
|
| + |
}
|
| + |
}
|
| + |
|
| + |
/// [`Iterator`] for finding each [`Job`] where the [`Job::oid`] matches the
|
| + |
/// wanted commit. See [`Jobs::find_by_commit`].
|
| + |
pub struct FindByCommit<'a> {
|
| + |
jobs: Box<dyn Iterator<Item = Result<(ObjectId, Job), cob::store::Error>> + 'a>,
|
| + |
needle: Oid,
|
| + |
}
|
| + |
|
| + |
impl<'a> FindByCommit<'a> {
|
| + |
fn new<R>(jobs: &Jobs<'a, R>, needle: Oid) -> Result<Self, cob::store::Error>
|
| + |
where
|
| + |
R: ReadRepository + cob::Store<Namespace = NodeId>,
|
| + |
{
|
| + |
Ok(Self {
|
| + |
jobs: Box::new(jobs.all()?),
|
| + |
needle,
|
| + |
})
|
| + |
}
|
| + |
|
| + |
fn wanted(&self, job: &Job) -> bool {
|
| + |
self.needle == *job.oid()
|
| + |
}
|
| + |
}
|
| + |
|
| + |
impl Iterator for FindByCommit<'_> {
|
| + |
type Item = Result<(JobId, Job), cob::store::Error>;
|
| + |
|
| + |
fn next(&mut self) -> Option<Self::Item> {
|
| + |
let job = self.jobs.next()?;
|
| + |
job.and_then(|(id, job)| {
|
| + |
if self.wanted(&job) {
|
| + |
Ok(Some((JobId::from(id), job)))
|
| + |
} else {
|
| + |
self.next().transpose()
|
| + |
}
|
| + |
})
|
| + |
.transpose()
|
| + |
}
|
| |
}
|
| |
|
| |
impl<'a, R> Jobs<'a, R>
|