Skip to main content

RCondition

Enum RCondition 

Source
pub enum RCondition {
    Error {
        message: String,
        class: Vec<String>,
        data: Option<ConditionData>,
        call: ConditionCall,
    },
    Warning {
        message: String,
        class: Vec<String>,
        data: Option<ConditionData>,
        call: ConditionCall,
    },
    Message {
        message: String,
        class: Vec<String>,
        data: Option<ConditionData>,
        call: ConditionCall,
    },
    Condition {
        message: String,
        class: Vec<String>,
        data: Option<ConditionData>,
        call: ConditionCall,
    },
    Conversion {
        message: String,
        class: Vec<String>,
        data: Option<ConditionData>,
        call: ConditionCall,
    },
}
Expand description

Owned payload for structured R conditions.

#[derive(RCondition)] gives a struct or enum a conversion into this payload. Its #[condition(kind = warning)] (or error / message / condition) chooses the signal; an enum variant can override the kind. Convert with RCondition::from(value), then call defer to accompany a return value, or raise to leave Rust.

Raised by the error!(), warning!(), message!(), and condition!() macros via std::panic::panic_any. Caught by with_r_unwind_protect before the generic panic→string path and forwarded to R as a tagged SEXP with rust_* class layering. The defer_* family (crate::deferred_condition) queues the same payloads instead of panicking, so the call still returns its value.

Every variant carries the same four parts: the message, the user classes (prepended to the rust_* layering, empty for none), the optional data fields and the ConditionCall choice. All four are owned and Send, so the payload can be queued from a worker thread. Each variant is one kind of the tagged condition value (crate::error_value::kind).

Variants§

§

Error

Raised by error!(...) / error!(class = "...", ...), and by the Result<T, E> Err arm once reconstructed across a package boundary.

Fields

§message: String

Human-readable condition message.

§class: Vec<String>

User classes, most specific first, before the framework’s classes.

§data: Option<ConditionData>

Named fields attached to the R condition.

§call: ConditionCall

Call attribution policy; messages always omit the call.

§

Warning

Raised by warning!(...) / warning!(class = "...", ...).

Fields

§message: String

Human-readable condition message.

§class: Vec<String>

User classes, most specific first, before the framework’s classes.

§data: Option<ConditionData>

Named fields attached to the R condition.

§call: ConditionCall

Call attribution policy; messages always omit the call.

§

Message

Raised by message!(...), and queued by crate::defer_message(). Only the typed-payload path fills class (the macro has no class = form); the R helper layers it in front of rust_message like the other kinds. A message never reports a call, whatever call says.

Fields

§message: String

Human-readable condition message.

§class: Vec<String>

User classes, most specific first, before the framework’s classes.

§data: Option<ConditionData>

Named fields attached to the R condition.

§call: ConditionCall

Call attribution policy; messages always omit the call.

§

Condition

Raised by condition!(...) / condition!(class = "...", ...).

Fields

§message: String

Human-readable condition message.

§class: Vec<String>

User classes, most specific first, before the framework’s classes.

§data: Option<ConditionData>

Named fields attached to the R condition.

§call: ConditionCall

Call attribution policy; messages always omit the call.

§

Conversion

An argument error, kind = "conversion": raised by crate::arg_error! / ArgError::raise (built by RCondition::arg_error), and a failed argument conversion once reconstructed across a package boundary.

Fields

§message: String

Human-readable condition message.

§class: Vec<String>

User classes, most specific first, before the framework’s classes.

§data: Option<ConditionData>

Named fields attached to the R condition.

§call: ConditionCall

Call attribution policy; messages always omit the call.

Implementations§

Source§

impl RCondition

Source

pub fn raise(self) -> !

Leave the current Rust body with this condition.

The enclosing miniextendr guard forwards it to R with its kind and metadata intact. Like warning!, raising a warning still exits Rust: muffling it in R does not resume this Rust body. Use defer to keep computing and return a value.

Source

pub fn defer(self)

Queue this condition until the current guarded call returns.

Preserves its declared kind, classes, fields and call policy, including for a mixed-kind enum. Errors queued here stop R at that boundary.

Source

#[doc(hidden)]
pub fn into_parts(self) -> (&'static str, ErrParts)

Split into the kind (one of crate::error_value::kind) and the ErrParts (message, class, data, call choice) that crate::error_value::condition_parts_value builds the tagged value from.

Source

pub fn message(&self) -> &str

The condition message, as conditionMessage() would read it in R.

Use it on a condition catch_condition caught or capture collected, for example to put a cause’s text into a new message.

Source

pub fn with_parent(self, parent: RCondition) -> Self

This condition with parent as its cause, as rlang::abort(parent = ) chains conditions.

R gets the cause as the field e$parent: a condition object with its own classes, message and fields (and its own parent, if it has one), built like the condition itself but not signalled. The cause’s classes stay out of this condition’s class vector, so a handler written for the cause’s class does not catch this condition; code that wants the cause branches on it: inherits(e$parent, "pkg_error_config").

The cause reports the same call as this condition, or none when it was raised with call = none. A second with_parent replaces the first, and the cause replaces a data field this condition names parent.

ⓘ
match catch_condition(|| rebuild(&saved)) {
    Ok(value) => value,
    Err(cause) => RCondition::Error {
        message: format!("could not rebuild: {}", cause.message()),
        class: vec!["pkg_error_rebuild".into()],
        data: None,
        call: ConditionCall::Inherit,
    }
    .with_parent(cause)
    .raise(),
}
Source

fn into_tagged_rvalue(self) -> RValue

The condition as the tagged value the R raise helper reads (error, kind, class, call, data), in RValue form so it can travel inside another condition’s data (Self::with_parent).

Source

pub fn call(&self) -> ConditionCall

Which call the condition reports when R raises it: see ConditionCall.

Source

#[doc(hidden)]
pub fn arg_error( param: impl Into<String>, message: String, call: ConditionCall, ) -> Self

The payload of crate::arg_error! and ArgError::raise: the argument error of parameter param (its R name) with message.

kind = "conversion", e$param as the only data field, and the class CONVERSION_ERROR_CLASS_MARKER, which the generated R replaces with the crate’s conversion_error_class: the condition the wrapper’s own argument checks raise (.miniextendr_arg_error).

Source§

impl RCondition

Source

pub unsafe fn from_tagged_sexp(sexp: SEXP) -> Option<Self>

Reconstruct an RCondition::Error from a tagged SEXP produced by crate::error_value::make_rust_condition_value.

Returns Some(RCondition) when sexp has class "rust_condition_value" AND the "__rust_condition__" attribute is TRUE. Returns None for all other SEXPs (normal return values, R_NilValue, etc.).

Reconstructs the matching variant for each kind: "error"/"panic"/ "result_err"/"none_err"/"other_rust_error" → RCondition::Error (class, message, data and a ConditionCall::None choice kept; the kind itself is not carried by the variant); "conversion" → RCondition::Conversion, so an argument error keeps kind = "conversion" across a package boundary (and an crate::arg_error! its class marker, which the consumer’s wrapper resolves); "warning" → RCondition::Warning; "message" → RCondition::Message; "condition" → RCondition::Condition. Unknown kinds degrade to RCondition::Error with the kind string prefixed to the message.

§Safety

Must be called from R’s main thread.

Trait Implementations§

Source§

impl Debug for RCondition

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> RDebug for T
where T: Debug,

Source§

fn debug_str(&self) -> String

Get a compact debug string representation.
Source§

fn debug_str_pretty(&self) -> String

Get a pretty-printed debug string with indentation.
Source§

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

Method shim for RDebug::debug_str. Read more
Source§

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

Method shim for RDebug::debug_str_pretty. Read more
Source§

impl<T> SizeHint for T
where T: ?Sized,

Source§

default fn lower_bound(&self) -> usize

🔬This is a nightly-only experimental API. (core_io_internals)
Returns a lower bound on the number of elements this container-like item contains. For example, an array [u8; 12] could return any value between 0 and 12 inclusively as a correct implementation. Read more
Source§

default fn upper_bound(&self) -> Option<usize>

🔬This is a nightly-only experimental API. (core_io_internals)
Returns an upper bound on the number of elements this container-like item contains if it can be determined, otherwise None. Read more
Source§

final fn size_hint(&self) -> (usize, Option<usize>)

🔬This is a nightly-only experimental API. (core_io_internals)
Returns an estimate for the number of elements this container like type contains. Read more
Source§

impl<T> SizedTypeProperties for T

Source§

#[doc(hidden)]
const SIZE: usize = _

🔬This is a nightly-only experimental API. (sized_type_properties)
Source§

#[doc(hidden)]
const ALIGN: usize = _

🔬This is a nightly-only experimental API. (sized_type_properties)
Source§

#[doc(hidden)]
const ALIGNMENT: Alignment = _

🔬This is a nightly-only experimental API. (ptr_alignment_type)
Source§

#[doc(hidden)]
const IS_ZST: bool = _

🔬This is a nightly-only experimental API. (sized_type_properties)
true if this type requires no storage. false if its size is greater than zero. Read more
Source§

#[doc(hidden)]
const LAYOUT: Layout = _

🔬This is a nightly-only experimental API. (sized_type_properties)
Source§

#[doc(hidden)]
const MAX_SLICE_LEN: usize = _

🔬This is a nightly-only experimental API. (sized_type_properties)
The largest safe length for a [Self]. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.

Layout§

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: 80 bytes

Size for each variant:

  • Error: 79 bytes
  • Warning: 79 bytes
  • Message: 79 bytes
  • Condition: 79 bytes
  • Conversion: 79 bytes