add conversion macros
This commit is contained in:
parent
535bed743d
commit
500c9def86
|
|
@ -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};
|
||||||
|
|
|
||||||
10
src/opt.rs
10
src/opt.rs
|
|
@ -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::*;
|
||||||
|
|
|
||||||
10
src/ptr.rs
10
src/ptr.rs
|
|
@ -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::*;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user