use std::io;
use std::error::Error;
use thiserror::Error;
use crate::types::*;
use crate::glue::*;
#[cfg_attr(feature = "cache", doc = " cache: &Default::default(),")]
#[cfg_attr(feature = "cache", doc = " cache_handle_config: Default::default(),")]
pub struct Job<'a> {
pub context: &'a JobContext,
pub cleaner: &'a Cleaner<'a>,
#[cfg(feature = "cache")]
pub cache: &'a Cache,
#[cfg(feature = "cache")]
pub cache_handle_config: CacheHandleConfig,
pub unthreader: &'a Unthreader,
pub lazy_task_configs: Box<dyn Iterator<Item = Result<LazyTaskConfig<'a>, GetLazyTaskConfigError>> + 'a>
}
impl ::core::fmt::Debug for Job<'_> {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
let mut x = f.debug_struct("Job");
x.field("context", &self.context);
x.field("cleaner" , &self.cleaner);
#[cfg(feature = "cache")]
x.field("cache" , &self.cache);
#[cfg(feature = "cache")]
x.field("cache_handle_config", &self.cache_handle_config);
x.field("unthreader", &self.unthreader);
x.field("lazy_task_configs", &"...");
x.finish()
}
}
impl<'a> Iterator for Job<'a> {
type Item = Result<LazyTask<'a>, MakeLazyTaskError>;
fn next(&mut self) -> Option<Self::Item> {
Some(match self.lazy_task_configs.next()? {
Ok(config) => Ok(LazyTask {
config,
job_context: self.context,
cleaner: self.cleaner,
#[cfg(feature = "cache")]
cache: CacheHandle {
cache: self.cache,
config: self.cache_handle_config
},
unthreader: self.unthreader
}),
Err(e) => Err(e.into())
})
}
}
#[derive(Debug, Error)]
pub enum GetLazyTaskConfigError {
#[error(transparent)]
IoError(#[from] io::Error),
#[error(transparent)]
Other(#[from] Box<dyn Error + Send>)
}
#[derive(Debug, Error)]
pub enum MakeLazyTaskError {
#[error(transparent)]
GetLazyTaskConfigError(#[from] GetLazyTaskConfigError)
}