add conversion macros

This commit is contained in:
numzero 2026-05-07 20:25:51 +03:00
parent 535bed743d
commit 500c9def86
3 changed files with 21 additions and 1 deletions

View File

@ -1,4 +1,4 @@
pub mod opt; pub mod opt;
pub mod ptr; pub mod ptr;
pub use ptr::OwnRef; pub use ptr::{OwnRef, to_own_ref};

View File

@ -40,6 +40,16 @@ impl<T> OwnRef<'_, T> {
} }
} }
#[macro_export]
macro_rules! _to_opt_own_ref {
($var:ident) => {
let mut $var = Some($var);
let $var = OwnRef::from_option(&mut $var);
};
}
pub use _to_opt_own_ref as to_own_ref;
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::*; use super::*;

View File

@ -66,6 +66,16 @@ impl OwnRef<'_, dyn std::any::Any> {
} }
} }
#[macro_export]
macro_rules! _to_ptr_own_ref {
($var:ident) => {
let mut $var = ManuallyDrop::new($var);
let $var = unsafe { OwnRef::from_manually_drop(&mut $var) };
};
}
pub use _to_ptr_own_ref as to_own_ref;
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::*; use super::*;