macro_rules! new_ref {
($r: ident, $p: ident, $gr: ident, $($bm:tt)*) => {
impl<T, M: $($bm)*> $r<T, M> {
#[inline]
pub fn new(t: T) -> Self { $p::new(t).$gr().unwrap() }
}
impl<M: $($bm)*> $r<str, M> {
#[inline]
pub fn new_str(t: &str) -> Self { $p::new_str(t).$gr().unwrap() }
}
impl<T, M: $($bm)*> $r<[T], M> {
#[inline]
pub fn new_slice<I: ExactSizeIterator<Item=T>>(t: I) -> Self { $p::new_slice(t).$gr().unwrap() }
}
impl<T: Default, M: $($bm)*> Default for $r<T, M> {
#[inline]
fn default() -> Self { $r::new(Default::default()) }
}
impl<T, M: $($bm)*> From<T> for $r<T, M> {
#[inline]
fn from(t: T) -> Self { $r::new(t) }
}
}
}
macro_rules! impl_get_refmut {
() => {
#[inline]
#[deprecated(note="Renamed to get_refmut")]
pub fn get_mut(&self) -> RefMut<T, M> { self.0.get_refmut().unwrap() }
#[inline]
#[deprecated(note="Renamed to try_get_refmut")]
pub fn try_get_mut(&self) -> Result<RefMut<T, M>, State> { self.0.get_refmut() }
#[inline]
pub fn get_refmut(&self) -> RefMut<T, M> { self.0.get_refmut().unwrap() }
#[inline]
pub fn try_get_refmut(&self) -> Result<RefMut<T, M>, State> { self.0.get_refmut() }
}
}
macro_rules! impl_get_ref {
() => {
#[inline]
pub fn get_ref(&self) -> Ref<T, M> { self.0.get_ref().unwrap() }
#[inline]
pub fn try_get_ref(&self) -> Result<Ref<T, M>, State> { self.0.get_ref() }
#[inline]
#[deprecated(note="Renamed to get_ref")]
pub fn get(&self) -> Ref<T, M> { self.get_ref() }
#[inline]
#[deprecated(note="Renamed to try_get_ref")]
pub fn try_get(&self) -> Result<Ref<T, M>, State> { self.0.get_ref() }
}
}
macro_rules! impl_ref_all {
() => {
#[inline]
pub fn get_weak(&self) -> Weak<T, M> { self.0.get_weak().unwrap() }
#[inline]
pub fn get_strong(&self) -> Strong<T, M> { self.0.get_strong().unwrap() }
#[inline]
pub fn try_get_weak(&self) -> Result<Weak<T, M>, State> { self.0.get_weak() }
#[inline]
pub fn try_get_strong(&self) -> Result<Strong<T, M>, State> { self.0.get_strong() }
#[inline]
pub fn state(&self) -> State { self.0.state() }
#[inline]
pub fn unpoison(&self) -> Result<(), State> { self.0.unpoison() }
}
}
macro_rules! impl_arc_all {
($t: ident, $drop_expr: expr) => {
unsafe impl<T: Send + Sync, M: Send + Sync + BitMask<Num=usize>> Send for $t<T, M> {}
unsafe impl<T: Send + Sync, M: Send + Sync + BitMask<Num=usize>> Sync for $t<T, M> {}
impl<T: ?Sized + Repr, M: BitMask<Num=usize>> Drop for $t<T, M> {
#[inline]
fn drop(&mut self) {
self.0.try_drop($drop_expr);
}
}
}
}
macro_rules! impl_deref_and_friends {
($r: ident, $($bm:tt)*) => {
impl<T: ?Sized + Repr, M: $($bm)*> ops::Deref for $r<T, M> {
type Target = T;
#[inline]
fn deref(&self) -> &Self::Target { unsafe { &*self.0.value_ptr() }}
}
unsafe impl<T: ?Sized + Repr, M: $($bm)*> crate::StableDeref for $r<T, M> {}
impl<T: ?Sized + Repr + fmt::Display, M: $($bm)*> fmt::Display for $r<T, M> {
#[inline]
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fmt::Display::fmt(&**self, f) }
}
impl<T: ?Sized + Repr, M: $($bm)*> borrow::Borrow<T> for $r<T, M> {
#[inline]
fn borrow(&self) -> &T { &**self }
}
impl<T: ?Sized + Repr, M: $($bm)*> convert::AsRef<T> for $r<T, M> {
#[inline]
fn as_ref(&self) -> &T { &**self }
}
impl<T: ?Sized + Repr + hash::Hash, M: $($bm)*> hash::Hash for $r<T, M> {
#[inline]
fn hash<H>(&self, state: &mut H) where H: hash::Hasher { (**self).hash(state) }
}
impl<T: ?Sized + Repr + PartialEq, M: $($bm)*> PartialEq for $r<T, M> {
#[inline]
fn eq(&self, other: &Self) -> bool { **self == **other }
#[inline]
fn ne(&self, other: &Self) -> bool { **self != **other }
}
impl<T: ?Sized + Repr + Eq, M: $($bm)*> Eq for $r<T, M> {}
impl<T: ?Sized + Repr + PartialOrd, M: $($bm)*> PartialOrd for $r<T, M> {
#[inline]
fn partial_cmp(&self, other: &Self) -> Option<cmp::Ordering> { (**self).partial_cmp(&**other) }
#[inline]
fn lt(&self, other: &Self) -> bool { **self < **other }
#[inline]
fn le(&self, other: &Self) -> bool { **self <= **other }
#[inline]
fn gt(&self, other: &Self) -> bool { **self > **other }
#[inline]
fn ge(&self, other: &Self) -> bool { **self >= **other }
}
impl<T: ?Sized + Repr + Ord, M: $($bm)*> Ord for $r<T, M> {
#[inline]
fn cmp(&self, other: &Self) -> cmp::Ordering { (**self).cmp(&**other) }
}
}
}