pub struct Computed;Expand description
Marker type of a read-only R field computed from the Rust value (#1883).
Declare it as #[r_data(get = "Self::f")] pub f: Computed on a
#[derive(ExternalPtr)] struct with an RSidecar selector. get
names a plain Rust function fn(&Self) -> T with T: IntoR, resolved in
the struct’s module (a leading Self is the struct); it needs no
#[miniextendr]. The field holds no value: it is a zero-sized marker that
gives the computed field its place among the type’s R fields, so every
struct literal writes f: Computed once, as it writes _r: RSidecar.
#[derive(ExternalPtr)]
#[externalptr(s3)]
pub struct Engine {
inner: Model,
#[r_data] _r: RSidecar,
#[r_data(get = "Self::group_by")] pub group_by: Computed,
#[r_data(name = "keys")] pub r_keys: Sidecar<SEXP>,
#[r_data(get = "Self::n_rows")] pub n_rows: Computed,
}
impl Engine {
fn group_by(&self) -> Vec<String> { self.inner.group_by.clone() }
fn n_rows(&self) -> i32 { self.inner.n_rows() }
}What the derive generates for it:
- the standalone getter
Engine_get_group_by(x), and an arm in the$/[[field methods ofs3(r_data_accessors)& co., at the field’s declared place among theSidecarand struct fields; - no setter: no
Engine_set_group_by(), and under the get/set form an assignment (x$group_by <- v) raisesminiextendr_read_only_field, as an R6 active binding does; an S7 property has no setter, so S7 refuses the assignment (#1888). An#[r_data(read_only)]field is read-only from R the same way (#2268).
The getter runs on R’s main thread with the live Rust value, so a
computed field refuses a pointer restored from a saved session like a
struct field does. Its errors are its own: a rust_error!(class = ...)
in the getter reaches R with that class. A getter returning
Result<T, E> is an error boundary, as a #[miniextendr] function’s
Result is (#2269): Ok reads the value, Err raises the error with
the classes and fields of its
RConditionData impl (else its serde
shape, else its Debug text), and Err(()) of a Result<T, ()> reads
NULL. The getter takes &Self, so it can’t read Sidecar values
(#1856), which are R fields already.
Only a pub Computed field reaches R.
Trait Implementations§
impl Copy for Computed
Source§impl Eq for Computed
impl Eq for Computed
1.0.0 (const: unstable) · Source§#[doc(hidden)]fn assert_receiver_is_total_eq(&self)
#[doc(hidden)]fn assert_receiver_is_total_eq(&self)
implementation detail of #[derive(Eq)]
Source§#[doc(hidden)]fn assert_fields_are_eq(&self)
#[doc(hidden)]fn assert_fields_are_eq(&self)
derive_eq_internals)impl StructuralPartialEq for Computed
impl TrivialClone for Computed
Auto Trait Implementations§
impl Forget for Computed
impl Freeze for Computed
impl RefUnwindSafe for Computed
impl Send for Computed
impl Sync for Computed
impl Unpin for Computed
impl UnsafeUnpin for Computed
impl UnwindSafe for Computed
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> ConsumingFallible for Twhere
T: Clone,
impl<T> Printable for T
Source§impl<T> RCopy for Twhere
T: Copy,
impl<T> RCopy for Twhere
T: Copy,
Source§impl<T> RDebug for Twhere
T: Debug,
impl<T> RDebug for Twhere
T: Debug,
Source§impl<T> SizeHint for Twhere
T: ?Sized,
impl<T> SizeHint for Twhere
T: ?Sized,
Source§default fn lower_bound(&self) -> usize
default fn lower_bound(&self) -> usize
core_io_internals)[u8; 12] could return any value between 0 and
12 inclusively as a correct implementation. Read moreSource§impl<T> SizedTypeProperties for T
impl<T> SizedTypeProperties for T
Source§#[doc(hidden)]const SIZE: usize
#[doc(hidden)]const SIZE: usize
sized_type_properties)Source§#[doc(hidden)]const ALIGN: usize
#[doc(hidden)]const ALIGN: usize
sized_type_properties)Source§#[doc(hidden)]const ALIGNMENT: Alignment
#[doc(hidden)]const ALIGNMENT: Alignment
ptr_alignment_type)Source§#[doc(hidden)]const IS_ZST: bool
#[doc(hidden)]const IS_ZST: bool
sized_type_properties)Source§#[doc(hidden)]const LAYOUT: Layout
#[doc(hidden)]const LAYOUT: Layout
sized_type_properties)Source§#[doc(hidden)]const MAX_SLICE_LEN: usize
#[doc(hidden)]const MAX_SLICE_LEN: usize
sized_type_properties)[Self]. Read moreLayout§
Note: Most layout information is completely unstable and may even differ between compilations. The only exception is types with certain repr(...) attributes. Please see the Rust Reference's “Type Layout” chapter for details on type layout guarantees.
Size: 0 bytes