Skip to main content

gen_delegating_default_impl

Function gen_delegating_default_impl 

Source
pub fn gen_delegating_default_impl(
    typ: &TypeDef,
    core_import: &str,
    type_name_prefix: &str,
    source_crate_remaps: &[(&str, &str)],
) -> String
Expand description

Generate an impl Default for BindingType that delegates to the core type’s Default.

Emitted when the core struct has a custom impl Default (typ.has_default == true) and the binding caller sets cfg.emit_delegating_default_impl = true. Without this delegation, the binding’s derived Default would use Rust’s primitive zeros (e.g. 0 for i64, String::new() for strings) and overwrite the core’s semantic defaults when partial JSON is deserialised via a struct-level #[serde(default)].

The generated impl requires that From<core::Type> for {type_name_prefix}{Type} exists. For PHP this is satisfied by gen_from_core_to_binding_cfg, which is emitted for every non-opaque convertible type in the binding crate.