use crate::codegen::generators::{AsyncPattern, RustBindingConfig};
pub(super) fn binding_config(core_import: &str, has_serde: bool) -> RustBindingConfig<'_> {
RustBindingConfig {
struct_attrs: &["pyclass(frozen, from_py_object)"],
field_attrs: &["pyo3(get)"],
struct_derives: &["Clone"],
method_block_attr: Some("pymethods"),
constructor_attr: "#[new]",
static_attr: Some("staticmethod"),
function_attr: "#[pyfunction]",
enum_attrs: &["pyclass(eq, eq_int, from_py_object)"],
enum_derives: &["Clone", "PartialEq"],
needs_signature: true,
signature_prefix: " #[pyo3(signature = (",
signature_suffix: "))]",
core_import,
async_pattern: AsyncPattern::Pyo3FutureIntoPy,
has_serde,
type_name_prefix: "",
option_duration_on_defaults: true,
opaque_type_names: &[],
skip_impl_constructor: false,
cast_uints_to_i32: false,
cast_large_ints_to_f64: false,
named_non_opaque_params_by_ref: false,
lossy_skip_types: &[],
serializable_opaque_type_names: &[],
never_skip_cfg_field_names: &[],
emit_delegating_default_impl: false,
skip_methods_when_not_delegatable: false,
}
}
pub(super) fn unsendable_binding_config(core_import: &str, has_serde: bool) -> RustBindingConfig<'_> {
RustBindingConfig {
struct_attrs: &["pyclass(unsendable, from_py_object)"],
..binding_config(core_import, has_serde)
}
}
pub(super) fn cfg_present_for_pyo3(cfg: &str) -> bool {
let normalized: String = cfg.chars().filter(|c| !c.is_whitespace()).collect();
if normalized == "not(target_arch=\"wasm32\")" {
return true;
}
if normalized.starts_with("feature=") {
return true;
}
if normalized.starts_with("any(") && normalized.ends_with(")") {
let inner = &normalized[4..normalized.len() - 1];
return inner
.split(',')
.all(|part| part.starts_with("feature=") || part == "not(target_arch=\"wasm32\")");
}
false
}