pub struct NrAny { /* private fields */ }Expand description
A type-erased value that can hold any data type.
This struct is #[repr(C)] and ABI-stable.
Implementations§
Source§impl NrAny
impl NrAny
Sourcepub fn new<T: Clone + Send + Sync + 'static>(value: T, type_tag: u32) -> Self
pub fn new<T: Clone + Send + Sync + 'static>(value: T, type_tag: u32) -> Self
Stores a clonable, thread-safe Rust value behind the ABI container.
Sourcepub fn from_bytes(bytes: &[u8], type_tag: u32) -> Self
pub fn from_bytes(bytes: &[u8], type_tag: u32) -> Self
Stores an owned copy of a byte slice as a Vec<u8>.
Sourcepub fn as_ptr<T>(&self) -> Result<*const T, NrStatus>
pub fn as_ptr<T>(&self) -> Result<*const T, NrStatus>
Returns a typed raw pointer after checking the stored byte size.
The user-defined type tag is not a Rust type identifier. The caller
must verify NrAny::type_tag before dereferencing the returned pointer.
pub fn as_mut_ptr<T>(&mut self) -> Result<*mut T, NrStatus>
pub fn is_null(&self) -> bool
pub fn type_tag(&self) -> u32
pub fn size(&self) -> u64
Trait Implementations§
Source§impl Clone for NrAny
impl Clone for NrAny
Source§fn clone(&self) -> Self
fn clone(&self) -> Self
Clone an NrAny.
§Safety / ABI v1 limitation
NrAny is type-erased and ABI v1 has no clone_fn in the struct.
Cloning a value that owns heap resources (i.e. has a drop_fn) by
memcpy would shallow-copy any inner pointers and cause a double-free
when both copies are dropped. Therefore:
- Null payload → returns
default()(null). drop_fn = None(POD payload) → safe deep copy via byte memcpy.drop_fn = Some(_)→ panics, because we cannot safely deep-copy without a type-awareclone_fn. Usedrop_fn = Noneand a POD representation, or wait for ABI v2 which addsclone_fn.
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreimpl Send for NrAny
impl Sync for NrAny
Auto Trait Implementations§
impl Freeze for NrAny
impl RefUnwindSafe for NrAny
impl Unpin for NrAny
impl UnsafeUnpin for NrAny
impl UnwindSafe for NrAny
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more