Clean up error propagation
Signed-off-by: Nikolaos Karaolidis <nick@karaolidis.com>
This commit is contained in:
29
src/utils/macros.rs
Normal file
29
src/utils/macros.rs
Normal file
@@ -0,0 +1,29 @@
|
||||
#[macro_export]
|
||||
macro_rules! impl_from_enum {
|
||||
($source:ty, $target:ty, $( $variant:ident ),* ) => {
|
||||
impl From<$source> for $target {
|
||||
fn from(item: $source) -> Self {
|
||||
match item {
|
||||
$( <$source>::$variant => <$target>::$variant, )*
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<$target> for $source {
|
||||
fn from(item: $target) -> Self {
|
||||
match item {
|
||||
$( <$target>::$variant => <$source>::$variant, )*
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! create_send_await {
|
||||
($sender:expr, $action:expr, $($contents:expr),*) => {
|
||||
let (message, receiver) = $action($($contents),*);
|
||||
$sender.send(message).await.unwrap();
|
||||
receiver.await.unwrap()
|
||||
};
|
||||
}
|
Reference in New Issue
Block a user