pub(crate) struct SerdeErrorSpec {
pub shape: Option<Path>,
pub tag: Option<String>,
pub prefix: Option<String>,
pub skip: Vec<String>,
pub rename: Vec<(String, String)>,
pub types: Vec<(FieldType, String)>,
}Expand description
#[miniextendr(serde_error)]: derive the Err arm’s condition class and
data from the error type’s serde::Serialize output instead of the
RConditionData/Debug probe.
The enum variant (external tagging, or the tag field of an internally
tagged enum) becomes the member class <prefix>_<variant>; the payload
fields become the condition’s data. Defaults: tag = "kind",
prefix = "<crate>_error" (from CARGO_CRATE_NAME at expansion time).
Field control (#1457, #2207): skip("a", "b") drops payload fields by
name, rename(a = "b") splices field a as b, and as_character("a"),
as_integer(..), as_double(..), as_logical(..) give a field that atomic
R type. All name the field as it serializes, before any rename; a variant
that lacks the field is unaffected. The macro cannot see the error type’s
fields, so only the option grammar is checked here; a rename target may
not be one of the reserved condition slots, and a field takes one of skip
and the as_* options.
shape = PATH names a miniextendr_api::condition::SerdeErrorShape const
holding these options, applied before the function’s own (#2207). The
generated code passes both to serde_err_parts as runtime data: the named
shape, then the function’s options as an inline const shape.
The serde path itself needs no attribute: under the serde feature every
Result<T, E> with E: Serialize + Display takes it through the runtime
probe. A spec only exists to carry options, so the bare flag and the
boolean forms are rejected with SERDE_ERROR_BARE_HELP.
Fields§
§shape: Option<Path>A named SerdeErrorShape (shape = PATH), applied before the options
below.
tag: Option<String>Internally-tagged discriminator field name (#[serde(tag = "...")]).
prefix: Option<String>Condition class prefix (family class).
skip: Vec<String>Payload fields dropped from the condition data.
rename: Vec<(String, String)>Payload fields spliced under another name: (from, to).
types: Vec<(FieldType, String)>Payload fields given an atomic R type (as_character(..) & co.), in
written order.
Implementations§
Source§impl SerdeErrorSpec
impl SerdeErrorSpec
Sourcefn from_metas<'a>(
metas: impl IntoIterator<Item = &'a Meta>,
span: Span,
) -> Result<Self>
fn from_metas<'a>( metas: impl IntoIterator<Item = &'a Meta>, span: Span, ) -> Result<Self>
Parse serde_error(...) contents: a comma-separated list of options.
Every problem is reported at once.
fn apply(&mut self, meta: &Meta, errors: &mut Vec<Error>)
Sourcepub(crate) fn with_self_type(&self, ty: &Ident) -> Self
pub(crate) fn with_self_type(&self, ty: &Ident) -> Self
A method’s spec with shape = Self::X naming the impl’s type: the C
wrapper that reads the shape is a free function, where Self doesn’t
resolve. The type ident takes the Self token’s span.
Sourcefn field_type(&self, name: &str) -> Option<FieldType>
fn field_type(&self, name: &str) -> Option<FieldType>
The as_* option that names name, if any.
Sourcepub(crate) fn own_shape(&self) -> Option<TokenStream>
pub(crate) fn own_shape(&self) -> Option<TokenStream>
The function’s own options as a SerdeErrorShape builder chain;
None when it only names a shape.
Trait Implementations§
Source§impl Clone for SerdeErrorSpec
impl Clone for SerdeErrorSpec
Source§impl Debug for SerdeErrorSpec
impl Debug for SerdeErrorSpec
Source§impl Default for SerdeErrorSpec
impl Default for SerdeErrorSpec
Source§impl Eq for SerdeErrorSpec
impl Eq for SerdeErrorSpec
Source§#[doc(hidden)]fn assert_fields_are_eq(&self)
#[doc(hidden)]fn assert_fields_are_eq(&self)
derive_eq_internals)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§impl PartialEq for SerdeErrorSpec
impl PartialEq for SerdeErrorSpec
impl StructuralPartialEq for SerdeErrorSpec
Auto Trait Implementations§
impl !Send for SerdeErrorSpec
impl !Sync for SerdeErrorSpec
impl Freeze for SerdeErrorSpec
impl RefUnwindSafe for SerdeErrorSpec
impl Unpin for SerdeErrorSpec
impl UnsafeUnpin for SerdeErrorSpec
impl UnwindSafe for SerdeErrorSpec
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,
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: 176 bytes