Beautify cal_on_store_by_handle!{} macro syntax

This commit is contained in:
Matthias Beyer 2017-01-21 19:53:32 +01:00
parent 04363035c2
commit c2b146aad8
2 changed files with 65 additions and 47 deletions

View file

@ -90,7 +90,8 @@ macro_rules! call_on_fle_from_store {
($itself:ident ($wrapper:ident) -> $name:ident -> $operation:block) => {{ ($itself:ident ($wrapper:ident) -> $name:ident -> $operation:block) => {{
let handle = $itself.get_data(&*$wrapper); let handle = $itself.get_data(&*$wrapper);
let store_handle = handle.store_handle(); let store_handle = handle.store_handle();
call_on_store_by_handle!(store_handle -> store -> { call_on_store_by_handle! {
store_handle named store inside {
match store.get(handle.fle_handle().clone()) { match store.get(handle.fle_handle().clone()) {
Ok(Some(mut $name)) => { Ok(Some(mut $name)) => {
$operation $operation
@ -104,12 +105,14 @@ macro_rules! call_on_fle_from_store {
NilClass::new().to_any_object() NilClass::new().to_any_object()
}, },
} }
}) }
}
}}; }};
($itself:ident ($wrapper:ident) -> $name:ident -> $operation: block on fail return $ex:expr) => {{ ($itself:ident ($wrapper:ident) -> $name:ident -> $operation: block on fail return $ex:expr) => {{
let handle = $itself.get_data(&*$wrapper); let handle = $itself.get_data(&*$wrapper);
let store_handle = handle.store_handle(); let store_handle = handle.store_handle();
call_on_store_by_handle!(store_handle -> store -> { call_on_store_by_handle! {
store_handle named store inside {
match store.get(handle.fle_handle().clone()) { match store.get(handle.fle_handle().clone()) {
Ok(Some(mut $name)) => { Ok(Some(mut $name)) => {
$operation $operation
@ -123,7 +126,8 @@ macro_rules! call_on_fle_from_store {
$ex $ex
}, },
} }
}) }
}
}}; }};
} }

View file

@ -41,11 +41,20 @@ impl_unwrap!(RStore, StoreHandle, STORE_WRAPPER);
impl_verified_object!(RStore); impl_verified_object!(RStore);
macro_rules! call_on_store_by_handle { macro_rules! call_on_store_by_handle {
($store_handle:ident -> $name:ident -> $operation:block) => {{ {
call_on_store_by_handle!($store_handle -> $name -> $operation on fail return NilClass::new().to_any_object()) $store_handle:ident named $name:ident inside $operation:block
}=> {{
call_on_store_by_handle! {
$store_handle
named $name
inside $operation
on fail return NilClass::new().to_any_object()
}
}}; }};
($store_handle:ident -> $name:ident -> $operation:block on fail return $ex:expr) => {{ {
$store_handle:ident named $name:ident inside $operation:block on fail return $ex:expr
} => {{
use cache::RUBY_STORE_CACHE; use cache::RUBY_STORE_CACHE;
let arc = RUBY_STORE_CACHE.clone(); let arc = RUBY_STORE_CACHE.clone();
@ -92,7 +101,8 @@ macro_rules! call_on_store {
on fail return $fail_expr:expr on fail return $fail_expr:expr
} => { } => {
let handle = $itself.get_data(&*$wrapper); let handle = $itself.get_data(&*$wrapper);
call_on_store_by_handle!(handle -> $store_name -> { call_on_store_by_handle! {
handle named $store_name inside {
let $fle_name = match $store_name.get($fle_handle_name) { let $fle_name = match $store_name.get($fle_handle_name) {
Ok(Some(fle)) => fle, Ok(Some(fle)) => fle,
Ok(None) => { Ok(None) => {
@ -105,7 +115,9 @@ macro_rules! call_on_store {
}, },
}; };
$operation $operation
} on fail return $fail_expr) }
on fail return $fail_expr
}
}; };
{ {
@ -114,7 +126,9 @@ macro_rules! call_on_store {
on fail return $fail_expr:expr on fail return $fail_expr:expr
} => { } => {
let handle = $itself.get_data(&*$wrapper); let handle = $itself.get_data(&*$wrapper);
call_on_store_by_handle!(handle -> $store_name -> $operation on fail return $fail_expr) call_on_store_by_handle! {
handle named $store_name inside $operation on fail return $fail_expr
}
}; };
{ {
@ -122,7 +136,7 @@ macro_rules! call_on_store {
operation $block operation $block
} => { } => {
let handle = $itself.get_data(&*$wrapper); let handle = $itself.get_data(&*$wrapper);
call_on_store_by_handle!(handle -> $name -> $operation) call_on_store_by_handle! { handle named $name inside $operation }
}; };
} }