pub trait RCopy {
// Required methods
fn copy(&self) -> Self;
fn is_copy(&self) -> bool;
}Expand description
Adapter trait for std::marker::Copy.
Indicates that a type can be cheaply copied (bitwise copy, no heap allocation). This is useful for R users to know that copying is O(1) and doesn’t involve deep cloning of heap data.
§Methods
copy()- Create a bitwise copy of this valueis_copy()- Returns true (useful for runtime type checking in R)
§Difference from RClone
Both RCopy and RClone create copies, but:
RCopy: Only for types where copying is cheap (stack-only, no heap)RClone: For any clonable type (may involve heap allocation)
If a type implements both, prefer copy() when you know copies are frequent.
§Example
ⓘ
#[derive(Copy, Clone, ExternalPtr)]
struct Point { x: f64, y: f64 }
#[miniextendr]
impl RCopy for Point {}In R:
p1 <- Point$new(1.0, 2.0)
p2 <- p1$copy() # Cheap bitwise copy
p1$is_copy() # TRUERequired Methods§
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.