Skip to main content

RustBindingConfig

Struct RustBindingConfig 

Source
pub struct RustBindingConfig<'a> {
Show 25 fields pub struct_attrs: &'a [&'a str], pub field_attrs: &'a [&'a str], pub struct_derives: &'a [&'a str], pub method_block_attr: Option<&'a str>, pub constructor_attr: &'a str, pub static_attr: Option<&'a str>, pub function_attr: &'a str, pub enum_attrs: &'a [&'a str], pub enum_derives: &'a [&'a str], pub needs_signature: bool, pub signature_prefix: &'a str, pub signature_suffix: &'a str, pub core_import: &'a str, pub async_pattern: AsyncPattern, pub has_serde: bool, pub type_name_prefix: &'a str, pub option_duration_on_defaults: bool, pub opaque_type_names: &'a [String], pub skip_impl_constructor: bool, pub cast_uints_to_i32: bool, pub cast_large_ints_to_f64: bool, pub named_non_opaque_params_by_ref: bool, pub lossy_skip_types: &'a [String], pub serializable_opaque_type_names: &'a [String], pub never_skip_cfg_field_names: &'a [String],
}
Expand description

Configuration for Rust binding code generation.

Fields§

§struct_attrs: &'a [&'a str]

Attrs applied to generated structs, e.g. ["pyclass(frozen)"].

§field_attrs: &'a [&'a str]

Attrs applied to each field, e.g. ["pyo3(get)"].

§struct_derives: &'a [&'a str]

Derives applied to generated structs, e.g. ["Clone"].

§method_block_attr: Option<&'a str>

Attr wrapping the impl block, e.g. Some("pymethods").

§constructor_attr: &'a str

Attr placed on the constructor, e.g. "#[new]".

§static_attr: Option<&'a str>

Attr placed on static methods, e.g. Some("staticmethod").

§function_attr: &'a str

Attr placed on free functions, e.g. "#[pyfunction]".

§enum_attrs: &'a [&'a str]

Attrs applied to generated enums, e.g. ["pyclass(eq, eq_int)"].

§enum_derives: &'a [&'a str]

Derives applied to generated enums, e.g. ["Clone", "PartialEq"].

§needs_signature: bool

Whether the backend requires #[pyo3(signature = (...))]-style annotations.

§signature_prefix: &'a str

Prefix for the signature annotation, e.g. "#[pyo3(signature = (".

§signature_suffix: &'a str

Suffix for the signature annotation, e.g. "))]".

§core_import: &'a str

Core crate import path, e.g. "liter_llm". Used to generate calls into core.

§async_pattern: AsyncPattern

Async pattern supported by this backend.

§has_serde: bool

Whether serde/serde_json are available in the output crate’s dependencies. When true, the generator can use serde-based param conversion and add serde::Serialize derives. When false, non-convertible Named params fall back to gen_unimplemented_body.

§type_name_prefix: &'a str

Prefix for binding type names (e.g. “Js” for NAPI/WASM, “” for PyO3/PHP). Used in impl block targets: impl {prefix}{TypeName}.

§option_duration_on_defaults: bool

When true, non-optional Duration fields on has_default types are emitted as Option<u64> in the binding struct so that unset fields fall back to the core type’s Default implementation rather than Duration::ZERO. Used by PyO3 to prevent validation failures when request_timeout is unset.

§opaque_type_names: &'a [String]

Opaque type names. Structs with non-optional fields of these types skip Default/Serialize/Deserialize derives since opaque wrappers don’t impl them.

§skip_impl_constructor: bool

When true, the impl block constructor (fn new(...)) is suppressed regardless of whether the type has fields. Useful for backends (e.g. extendr) that generate a separate kwargs-style free-function constructor instead of an in-class new().

§cast_uints_to_i32: bool

When true, small unsigned/signed ints (u8, u16, u32, i8, i16) are cast from i32 in gen_lossy_binding_to_core_fields. Used by the extendr backend where R maps small ints to i32.

§cast_large_ints_to_f64: bool

When true, large int/size types (u64, usize, isize) are cast from f64 in gen_lossy_binding_to_core_fields. Used by the extendr backend where R maps large ints to f64.

§named_non_opaque_params_by_ref: bool

When true, Named non-opaque struct parameters in free function signatures are emitted as &T (reference) instead of T (owned). Required for the extendr backend because #[extendr] only generates TryFrom<&Robj> for &T, not for T, so owned struct params cannot be passed through the FFI layer.

§lossy_skip_types: &'a [String]

Types that have no From<BindingType> impl (e.g. output-only flat data enums). When gen_lossy_binding_to_core_fields encounters a field whose TypeRef::Named type is in this slice, it emits Default::default() instead of .clone().into().

§serializable_opaque_type_names: &'a [String]

Subset of opaque_type_names whose binding wrappers DO implement serde::Serialize/Deserialize (e.g. data-enum wrappers via gen_pyo3_data_enum, which emit forwarding impls delegating to the core type). Fields whose type references a name in this slice will NOT receive #[serde(skip)], even when the name is also in opaque_type_names. Required so from_json/to_json round-trips on parent structs (e.g. ChatCompletionRequest.messages: Vec<Message>) don’t silently drop the field to Default::default().

§never_skip_cfg_field_names: &'a [String]

Field names that should NOT be skipped even if they are cfg-gated. Used when the binding crate enables the feature that gates the field, so the field must appear in the binding struct and From impl. Typically populated from trait bridge options field names.

Auto Trait Implementations§

§

impl<'a> Freeze for RustBindingConfig<'a>

§

impl<'a> RefUnwindSafe for RustBindingConfig<'a>

§

impl<'a> Send for RustBindingConfig<'a>

§

impl<'a> Sync for RustBindingConfig<'a>

§

impl<'a> Unpin for RustBindingConfig<'a>

§

impl<'a> UnsafeUnpin for RustBindingConfig<'a>

§

impl<'a> UnwindSafe for RustBindingConfig<'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> 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, 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.