#[macro_export]
macro_rules! erased_handle {
($erased:ident : $leaf:path => $upcast:path) => {
impl ::core::convert::From<$erased> for $crate::HandleId {
fn from(handle: $erased) -> $crate::HandleId {
handle.id
}
}
impl ::core::cmp::PartialEq for $erased {
fn eq(&self, other: &$erased) -> bool {
self.id == other.id
}
}
impl ::core::cmp::Eq for $erased {}
impl ::core::hash::Hash for $erased {
fn hash<H: ::core::hash::Hasher>(&self, state: &mut H) {
::core::hash::Hash::hash(&self.id, state);
}
}
impl ::core::cmp::PartialEq<$crate::Retained<$erased>> for $erased {
fn eq(&self, other: &$crate::Retained<$erased>) -> bool {
self.id == other.handle().id
}
}
impl ::core::cmp::PartialEq<$erased> for &$crate::Retained<$erased> {
fn eq(&self, other: &$erased) -> bool {
self.handle().id == other.id
}
}
impl<Leaf: $leaf> ::core::convert::From<$crate::Handle<Leaf>> for $erased {
fn from(handle: $crate::Handle<Leaf>) -> $erased {
$upcast(handle)
}
}
impl $erased {
pub fn upgrade(
self,
app: &$crate::App,
) -> ::core::option::Option<$crate::Retained<$erased>> {
$crate::Retained::upgrade(app, self)
}
#[track_caller]
pub fn keep(self, app: &$crate::App) -> $crate::Retained<$erased> {
$crate::Retained::keep(app, self)
}
}
};
($erased:ident<$param:ident> : $leaf:ident => $upcast:path) => {
impl<$param: 'static> ::core::convert::From<$erased<$param>> for $crate::HandleId {
fn from(handle: $erased<$param>) -> $crate::HandleId {
handle.id
}
}
impl<$param: 'static> ::core::cmp::PartialEq for $erased<$param> {
fn eq(&self, other: &$erased<$param>) -> bool {
self.id == other.id
}
}
impl<$param: 'static> ::core::cmp::Eq for $erased<$param> {}
impl<$param: 'static> ::core::hash::Hash for $erased<$param> {
fn hash<H: ::core::hash::Hasher>(&self, state: &mut H) {
::core::hash::Hash::hash(&self.id, state);
}
}
impl<$param: 'static> ::core::cmp::PartialEq<$crate::Retained<$erased<$param>>>
for $erased<$param>
{
fn eq(&self, other: &$crate::Retained<$erased<$param>>) -> bool {
self.id == other.handle().id
}
}
impl<$param: 'static> ::core::cmp::PartialEq<$erased<$param>>
for &$crate::Retained<$erased<$param>>
{
fn eq(&self, other: &$erased<$param>) -> bool {
self.handle().id == other.id
}
}
impl<$param: 'static, Leaf: $leaf<$param>> ::core::convert::From<$crate::Handle<Leaf>>
for $erased<$param>
{
fn from(handle: $crate::Handle<Leaf>) -> $erased<$param> {
$upcast(handle)
}
}
impl<$param: 'static> $erased<$param> {
pub fn upgrade(
self,
app: &$crate::App,
) -> ::core::option::Option<$crate::Retained<$erased<$param>>> {
$crate::Retained::upgrade(app, self)
}
#[track_caller]
pub fn keep(self, app: &$crate::App) -> $crate::Retained<$erased<$param>> {
$crate::Retained::keep(app, self)
}
}
};
}