use std::cell::{RefCell, Ref, RefMut};
#[macro_export]
macro_rules! rfc_borrow
{
($this:ident, $func:expr) =>
{
rfc_borrow!($this, mut_state, $func)
};
($this:ident, $rfc_field:ident, $func:expr) =>
{
{
let mut_state_ref = $this.$rfc_field.borrow();
$func(mut_state_ref, &$this)
}
}
}
#[macro_export]
macro_rules! rfc_borrow_mut
{
($this:ident, $func:expr) =>
{
rfc_borrow_mut!($this, mut_state, $func)
};
($this:ident, $rfc_field:ident, $func:expr) =>
{
{
let mut_state_mut = $this.$rfc_field.borrow_mut();
$func(mut_state_mut, &$this)
}
}
}
#[macro_export]
macro_rules! rfc_borrow_2
{
($this:ident, $func:expr) =>
{
rfc_borrow_2!($this, mut_state, $func)
};
($this:ident, $rfc_field:ident, $func:expr) =>
{
{
let mut_state_ref = $this.$rfc_field.borrow();
$func(mut_state_ref, $this)
}
}
}
#[macro_export]
macro_rules! rfc_borrow_mut_2
{
($this:ident, $func:expr) =>
{
rfc_borrow_mut_2!($this, mut_state, $func)
};
($this:ident, $rfc_field:ident, $func:expr) =>
{
{
let mut_state_mut = $this.$rfc_field.borrow_mut();
$func(mut_state_mut, $this)
}
}
}
pub fn borrow<T, F, R>(rfc: &RefCell<T>, mut func: F) -> R
where F: FnMut(Ref<T>) -> R
{
let rfc_ref = rfc.borrow();
func(rfc_ref)
}
pub fn borrow_param<T, P, F, R>(rfc: &RefCell<T>, param: &P, mut func: F) -> R
where F: FnMut(Ref<T>, &P) -> R
{
let rfc_ref = rfc.borrow();
func(rfc_ref, param)
}
pub fn borrow_mut<T, F, R>(rfc: &RefCell<T>, mut func: F) -> R
where F: FnMut(RefMut<T>) -> R
{
let rfc_mut = rfc.borrow_mut();
func(rfc_mut)
}
pub fn borrow_mut_param<T, P, F, R>(rfc: &RefCell<T>, param: &P, mut func: F) -> R
where F: FnMut(RefMut<T>, &P) -> R
{
let rfc_mut = rfc.borrow_mut();
func(rfc_mut, param)
}
pub fn borrow_param_2<T, P, F, R>(rfc: &RefCell<T>, param: &mut P, mut func: F) -> R
where F: FnMut(Ref<T>, &mut P) -> R
{
let rfc_ref = rfc.borrow();
func(rfc_ref, param)
}
pub fn borrow_mut_param_2<T, P, F, R>(rfc: &RefCell<T>, param: &mut P, mut func: F) -> R
where F: FnMut(RefMut<T>, &mut P) -> R
{
let rfc_mut = rfc.borrow_mut();
func(rfc_mut, param)
}
pub fn borrow_param_3<T, P, F, R>(rfc: &RefCell<T>, param: &P, mut func: F) -> R
where F: FnMut(Ref<T>, P) -> R,
P: Clone
{
let rfc_ref = rfc.borrow();
func(rfc_ref, param.clone())
}
pub fn borrow_mut_param_3<T, P, F, R>(rfc: &RefCell<T>, param: &P, mut func: F) -> R
where F: FnMut(RefMut<T>, P) -> R,
P: Clone
{
let rfc_mut = rfc.borrow_mut();
func(rfc_mut, param.clone())
}
pub fn borrow_param_4<T, P, F, R>(rfc: &RefCell<T>, param: P, mut func: F) -> R
where F: FnMut(Ref<T>, P) -> R
{
let rfc_ref = rfc.borrow();
func(rfc_ref, param)
}
pub fn borrow_mut_param_4<T, P, F, R>(rfc: &RefCell<T>, param: P, mut func: F) -> R
where F: FnMut(RefMut<T>, P) -> R
{
let rfc_mut = rfc.borrow_mut();
func(rfc_mut, param)
}