Skip to main content

RCopy

Trait RCopy 

Source
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 value
  • is_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()       # TRUE

Required Methods§

Source

fn copy(&self) -> Self

Create a bitwise copy of this value.

For Copy types, this is always cheap (O(1), no heap allocation).

Source

fn is_copy(&self) -> bool

Check if this type implements Copy.

Always returns true for types implementing this trait. Useful for runtime type checking in R.

Provided Methods§

Source

#[doc(hidden)]
unsafe extern "C" fn __RCopy_copy_shim( data: *mut c_void, argc: i32, argv: *const SEXP, ) -> SEXP
where Self: Sized + RCopy + IntoR,

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.

Source

#[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,

Method shim for RCopy::is_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".

Implementors§

Source§

impl<T: Copy> RCopy for T