pub trait RCopy {
// Required methods
fn copy(&self) -> Self;
fn is_copy(&self) -> bool;
// Provided methods
#[doc(hidden)] unsafe extern "C" fn __RCopy_copy_shim(
data: *mut c_void,
argc: i32,
argv: *const SEXP,
) -> SEXP
where Self: Sized + RCopy + IntoR { ... }
#[doc(hidden)] unsafe extern "C" fn __RCopy_is_copy_shim(
data: *mut c_void,
argc: i32,
argv: *const SEXP,
) -> SEXP
where Self: Sized + RCopy + IntoR { ... }
}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 miniextendr_api::adapter_traits::RCopy for Point {}In R:
p1 <- Point$new(1.0, 2.0)
p2 <- p1$RCopy$copy() # Cheap bitwise copy
p1$RCopy$is_copy() # TRUERequired Methods§
Provided Methods§
Source#[doc(hidden)]unsafe extern "C" fn __RCopy_copy_shim(
data: *mut c_void,
argc: i32,
argv: *const SEXP,
) -> SEXP
#[doc(hidden)]unsafe extern "C" fn __RCopy_copy_shim(
data: *mut c_void,
argc: i32,
argv: *const SEXP,
) -> SEXP
Method shim for RCopy::copy.
Converts SEXP arguments, calls the method, and returns SEXP result.
Both Rust panics and R longjmps are caught via with_r_unwind_protect.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".