This commit is contained in:
Adrian Heine 2020-10-17 23:44:52 +02:00
parent b53267f406
commit da98bfba8c
20 changed files with 80 additions and 61 deletions

View file

@ -17,27 +17,14 @@ pub trait SymbolRunner {
) -> Result<bool, Box<dyn Error>>;
}
#[derive(Debug)]
pub enum SymbolRunError {
Symbol(Box<dyn Error>),
ExecuteDidNotReach(()),
}
#[derive(Debug, Default)]
pub struct ExecuteDidNotReachError;
impl Error for SymbolRunError {
fn cause(&self) -> Option<&dyn Error> {
match self {
Self::Symbol(ref e) => Some(&**e),
Self::ExecuteDidNotReach(_) => None,
}
}
}
impl Error for ExecuteDidNotReachError {}
impl fmt::Display for SymbolRunError {
impl fmt::Display for ExecuteDidNotReachError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::Symbol(ref e) => write!(f, "{}", e),
Self::ExecuteDidNotReach(_) => write!(f, "Target not reached after executing symbol"),
}
write!(f, "Target not reached after executing symbol")
}
}
@ -45,7 +32,8 @@ impl fmt::Display for SymbolRunError {
pub struct InitializingSymbolRunner;
impl InitializingSymbolRunner {
pub fn new() -> Self {
#[must_use]
pub const fn new() -> Self {
Self
}
@ -64,7 +52,7 @@ impl InitializingSymbolRunner {
if target_reached {
Ok(())
} else {
Err(Box::new(SymbolRunError::ExecuteDidNotReach(())))
Err(Box::new(ExecuteDidNotReachError))
}
}
}
@ -102,7 +90,8 @@ impl SymbolRunner for InitializingSymbolRunner {
pub struct DelayingSymbolRunner<R>(R);
impl<R> DelayingSymbolRunner<R> {
pub fn new(symbol_runner: R) -> Self {
#[must_use]
pub const fn new(symbol_runner: R) -> Self {
Self(symbol_runner)
}
}
@ -137,7 +126,8 @@ where
pub struct DrySymbolRunner;
impl DrySymbolRunner {
pub fn new() -> Self {
#[must_use]
pub const fn new() -> Self {
Self
}
}
@ -172,7 +162,8 @@ impl SymbolRunner for DrySymbolRunner {
pub struct ReportingSymbolRunner<R>(R);
impl<R> ReportingSymbolRunner<R> {
pub fn new(symbol_runner: R) -> Self {
#[must_use]
pub const fn new(symbol_runner: R) -> Self {
Self(symbol_runner)
}
}
@ -251,6 +242,7 @@ mod test {
T: Iterator<Item = Result<bool, Box<dyn Error>>>,
> DummySymbol<T, E>
{
#[must_use]
fn new<
IE: IntoIterator<IntoIter = E, Item = Result<(), Box<dyn Error>>>,
IT: IntoIterator<IntoIter = T, Item = Result<bool, Box<dyn Error>>>,