1
0
Fork 0
forked from wry/wry

macros: add opaque macro

This commit is contained in:
Julian Orth 2026-04-02 16:29:43 +02:00
parent 0a5b00f269
commit 9880f78ec4
16 changed files with 60 additions and 115 deletions

View file

@ -900,3 +900,36 @@ macro_rules! dynload {
});
};
}
macro_rules! opaque {
($ty:ident, $fun:ident) => {
#[derive(Debug, Eq, PartialEq, Copy, Clone, Hash, Ord, PartialOrd)]
pub struct $ty(crate::utils::opaque::Opaque);
unsafe impl crate::utils::clonecell::UnsafeCellCloneSafe for $ty {}
pub fn $fun() -> $ty {
$ty(crate::utils::opaque::opaque())
}
impl $ty {
pub fn to_string(self) -> arrayvec::ArrayString<{ crate::utils::opaque::OPAQUE_LEN }> {
self.0.to_string()
}
}
impl std::fmt::Display for $ty {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
self.0.fmt(f)
}
}
impl std::str::FromStr for $ty {
type Err = crate::utils::opaque::OpaqueError;
fn from_str(s: &str) -> Result<Self, Self::Err> {
Ok(Self(s.parse()?))
}
}
};
}