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.
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. The getter returns a value, not a
Result; it takes &Self, so it can’t read Sidecar values (#1856),
which are R fields already.
Only a pub Computed field reaches R, and only on S3, S4, env and
vctrs types: R6 active bindings and S7 properties need a setter (#1888).
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 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