86 lines
1.9 KiB
Rust
86 lines
1.9 KiB
Rust
#[macro_export]
|
|
macro_rules! handle_diagnostic {
|
|
( $result: expr, $diagnostics: expr ) => {
|
|
match $result {
|
|
Ok(_) => {}
|
|
Err(diagnostic) => {
|
|
$diagnostics.push(diagnostic);
|
|
}
|
|
}
|
|
};
|
|
}
|
|
|
|
#[macro_export]
|
|
macro_rules! handle_diagnostics {
|
|
( $result: expr, $diagnostics: expr ) => {
|
|
match $result {
|
|
Ok(_) => {}
|
|
Err(mut result_diagnostics) => {
|
|
$diagnostics.append(&mut result_diagnostics);
|
|
}
|
|
}
|
|
};
|
|
}
|
|
|
|
#[macro_export]
|
|
macro_rules! ok_or_return {
|
|
( $result: expr, $diagnostics: expr ) => {
|
|
match $result {
|
|
Ok(inner) => inner,
|
|
Err(mut diagnostics) => {
|
|
$diagnostics.append(&mut diagnostics);
|
|
return Err($diagnostics);
|
|
}
|
|
}
|
|
};
|
|
( $result: expr ) => {
|
|
match $result {
|
|
Ok(inner) => inner,
|
|
Err(diagnostics) => {
|
|
return Err(diagnostics);
|
|
}
|
|
}
|
|
};
|
|
}
|
|
|
|
#[macro_export]
|
|
macro_rules! maybe_return_diagnostics {
|
|
( $diagnostics: expr ) => {
|
|
if !$diagnostics.is_empty() {
|
|
return Err($diagnostics);
|
|
}
|
|
};
|
|
}
|
|
|
|
#[macro_export]
|
|
macro_rules! diagnostics_result {
|
|
( $diagnostics: expr ) => {
|
|
if $diagnostics.is_empty() {
|
|
Ok(())
|
|
} else {
|
|
Err($diagnostics)
|
|
}
|
|
};
|
|
}
|
|
|
|
#[macro_export]
|
|
macro_rules! ok_or_err_diagnostics {
|
|
( $to_return: expr, $diagnostics: expr ) => {
|
|
if $diagnostics.is_empty() {
|
|
Ok($to_return)
|
|
} else {
|
|
Err($diagnostics)
|
|
}
|
|
};
|
|
}
|
|
|
|
#[macro_export]
|
|
macro_rules! push_ok_or_push_errs {
|
|
( $result: expr, $oks: expr, $errs: expr ) => {
|
|
match $result {
|
|
Ok(inner) => $oks.push(inner),
|
|
Err(mut errs) => $errs.append(&mut errs),
|
|
}
|
|
};
|
|
}
|