1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
//! Support for falling back to a nested type's own zero-argument initializer when decoding a
//! `#[serde(default)]` field whose default is `Type::default()` (`typed_default == Empty`).
//!
//! Lives in its own file because `gen_bindings/dto.rs` — the only caller — is at its recorded
//! file-size ceiling (`tests/file_size_baseline.txt`) and may not grow. See
//! `backends::swift::named_serde_default_tests` for the companion test coverage, kept out of
//! `dto.rs` for the same reason.
use crateswift_typed_default_literal;
use cratebinding_fields;
use crate;
use HashSet;
/// Computes the subset of `known_dto_names` whose generated memberwise `public init` accepts
/// zero arguments — i.e. every visible field either renders a Swift literal default
/// (`= <literal>`) or is Optional (`= nil`), the exact per-field rule `emit_first_class_struct`'s
/// `params` loop uses to decide whether a parameter carries a default.
///
/// A name in this set can stand in for its own Rust `Default::default()` inside another type's
/// decoder as a bare `TypeName()` call: that call is guaranteed to compile, and — because it
/// runs through the same defaults the memberwise init encodes — reconstructs the same field
/// values `Default::default()` would produce in Rust. See [`zero_arg_named_default`].
///
/// Enums are never members: `api.types` holds only structs, so a unit or data-variant serde enum
/// in `known_dto_names` is silently excluded. Swift gives no bare `EnumName()` constructor, and
/// for an `impl Default for SomeEnum` gated behind Cargo features, alef has no way to know which
/// variant it resolves to.
///
/// No fixed-point iteration is needed (unlike `compute_first_class_dto_names`): a field whose own
/// type is `Named` and defaults via `Empty` is *not* given a default at its container's
/// init-parameter level, so nesting cannot make an otherwise-non-constructible type
/// constructible — each type's membership depends only on its own fields, never on another
/// type's membership. ~keep
pub
/// The `TypeName()` fallback for a non-Optional `Named` field decoding its own `Empty` default.
///
/// `swift_type_based_default` has no zero for `Named` — a struct's "zero" is whatever its own
/// fields default to, not a value that function can invent. When `zero_arg_constructible_names`
/// (from [`compute_zero_arg_constructible_names`]) says the named type's own memberwise init
/// takes zero arguments, `TypeName()` runs that same init and reconstructs the exact
/// `Default::default()` value, so it is a safe fallback rather than a guess. Anything else —
/// an enum, a struct with a required field of its own, or a `typed_default` other than `Empty` —
/// returns `None` and leaves the caller's required `decode` in place. ~keep
pub