Skip to main content

ConversionConfig

Struct ConversionConfig 

Source
pub struct ConversionConfig<'a> {
Show 16 fields pub type_name_prefix: &'a str, pub cast_large_ints_to_i64: bool, pub enum_string_names: Option<&'a AHashSet<String>>, pub map_uses_jsvalue: bool, pub cast_f32_to_f64: bool, pub optionalize_defaults: bool, pub json_to_string: bool, pub include_cfg_metadata: bool, pub option_duration_on_defaults: bool, pub binding_enums_have_data: bool, pub exclude_types: &'a [String], pub vec_named_to_string: bool, pub map_as_string: bool, pub opaque_types: Option<&'a AHashSet<String>>, pub source_crate_remaps: &'a [(&'a str, &'a str)], pub binding_field_renames: Option<&'a HashMap<String, String>>,
}
Expand description

Backend-specific configuration for From/field conversion generation. Enables shared code to handle all backend differences via parameters.

Fields§

§type_name_prefix: &'a str

Prefix for binding type names (“Js” for NAPI/WASM, “” for others).

§cast_large_ints_to_i64: bool

U64/Usize/Isize need as i64 casts (NAPI, PHP — JS/PHP lack native u64).

§enum_string_names: Option<&'a AHashSet<String>>

Enum names mapped to String in the binding layer (PHP only). Named fields referencing these use format!("{:?}") in core→binding.

§map_uses_jsvalue: bool

Map types use JsValue in the binding layer (WASM only). When true, Map fields use serde_wasm_bindgen for conversion instead of iterator-based collect patterns (JsValue is not iterable).

§cast_f32_to_f64: bool

When true, f32 is mapped to f64 (NAPI only — JS has no f32).

§optionalize_defaults: bool

When true, non-optional fields on defaultable types are wrapped in Option in the binding struct and need .unwrap_or_default() in binding→core From. Used by NAPI to make JS-facing structs fully optional.

§json_to_string: bool

When true, Json (serde_json::Value) fields are mapped to String in the binding layer. Core→binding uses .to_string(), binding→core uses Default::default() (lossy). Used by PHP where serde_json::Value can’t cross the extension boundary.

§include_cfg_metadata: bool

When true, add synthetic metadata field conversion for ConversionResult. Only NAPI backend sets this (it adds metadata field to the struct).

§option_duration_on_defaults: bool

When true, non-optional Duration fields on has_default types are stored as Option<u64> in the binding struct. The From conversion uses the builder pattern so that None falls back to the core type’s Default implementation (giving the real default, e.g. Duration::from_secs(30)) instead of Duration::ZERO. Used by PyO3 to prevent validation failures when request_timeout is unset.

§binding_enums_have_data: bool

When true, binding enums include data variant fields (Magnus). When false (default), binding enums are unit-only and data is lost in conversion.

§exclude_types: &'a [String]

Type names excluded from the binding layer. Fields referencing these types are skipped in the binding struct and defaulted in From conversions. Used by WASM to handle types excluded due to native dependency requirements.

§vec_named_to_string: bool

When true, Vec fields are stored as JSON strings in the binding layer. Core→binding uses serde_json::to_string, binding→core uses serde_json::from_str. Used by Magnus (Ruby) where Vec cannot cross the FFI boundary directly and is collapsed to String by field_type_for_serde’s catch-all arm.

§map_as_string: bool

When true, all Map(K, V) fields are stored as a plain String in the binding layer. Core→binding uses format!("{:?}", val.field), binding→core uses Default::default() (lossy). Used by Rustler (Elixir NIFs) where HashMap cannot cross the NIF boundary directly.

§opaque_types: Option<&'a AHashSet<String>>

Set of opaque type names in the binding layer. When a field has CoreWrapper::Arc and its type is an opaque Named type, the binding wrapper holds inner: Arc<CoreT> and the conversion must extract .inner directly instead of calling .into() + wrapping in Arc::new.

§source_crate_remaps: &'a [(&'a str, &'a str)]

When core_crate_override is set for a language, the IR’s rust_path values still contain the original source crate prefix (e.g. spikard_core::Method). This field remaps those paths: (original_crate_name, override_crate_name). When set, any rust_path whose leading crate segment equals original_crate_name is rewritten to use override_crate_name instead. Example: Some(("spikard_core", "spikard_http")) rewrites spikard_core::Methodspikard_http::Method.

§binding_field_renames: Option<&'a HashMap<String, String>>

Per-field binding name overrides. Key is "TypeName.field_name" (using the original IR field name); value is the binding struct’s actual Rust field name (e.g. "class_"). Used when a field name is a reserved keyword in the target language and must be escaped in the binding struct (e.g. classclass_).

When present, val.<binding_name> is used for binding-side access and the original field_name is used for core-side access (struct literal and assignment targets).

Implementations§

Source§

impl<'a> ConversionConfig<'a>

Source

pub fn binding_field_name<'b>( &self, type_name: &str, field_name: &'b str, ) -> &'b str
where 'a: 'b,

Look up the binding struct field name for a given type and IR field name.

Returns the escaped name (e.g. "class_") when the field was renamed due to a reserved keyword conflict, or the original field_name when no rename applies.

Source

pub fn binding_field_name_owned( &self, type_name: &str, field_name: &str, ) -> String

Like binding_field_name but returns an owned String, suitable for use in format strings and string interpolation.

Trait Implementations§

Source§

impl<'a> Clone for ConversionConfig<'a>

Source§

fn clone(&self) -> ConversionConfig<'a>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'a> Default for ConversionConfig<'a>

Source§

fn default() -> ConversionConfig<'a>

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<'a> Freeze for ConversionConfig<'a>

§

impl<'a> RefUnwindSafe for ConversionConfig<'a>

§

impl<'a> Send for ConversionConfig<'a>

§

impl<'a> Sync for ConversionConfig<'a>

§

impl<'a> Unpin for ConversionConfig<'a>

§

impl<'a> UnsafeUnpin for ConversionConfig<'a>

§

impl<'a> UnwindSafe for ConversionConfig<'a>

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more