API style: argument clarity
Rust has no named arguments, so Day emulates their clarity where it pays and keeps SwiftUI-like terseness where it doesn’t. The rule, in priority order:
-
No bare
bool(or otherwise unreadable literal) in a public signature. A call site must not readd.text(…, true). Use a two-variant enum (TextAnchor::Centered,Boundary::Yes) or a builder toggle instead. -
Required bundles of 3+ concrete-typed values → a struct parameter with named fields at the call site. This is the closest Rust gets to named arguments:
d.text("40", center, TextStyle { size: 22.0, color: accent, anchor: TextAnchor::Centered });This is already the house style at the spec boundary (
NavProps { title, split },TextFieldPatch::Text { text, from_native }); apply it to app-facing APIs whenever the fields are concrete types. -
Generic-ergonomic constructors keep ≤3 positional, type-distinct arguments.
route("controls", tr("nav-controls"), controls_page)stays positional: the three types are mutually incompatible, so every mis-ordering is a compile error, and funnelingimpl IntoText<M>through struct fields would force.into()/Box::newnoise at every call site (struct literals don’t do implicit conversion). Names would cost more ergonomics than they buy. -
Optional configuration → builder methods (
.spacing(8.0),.align(…),.padding(16.0)). Never grow a constructor’s positional list for options. -
Conventional-order exemptions. Universally-fixed orders stay positional even with same-typed arguments:
Color::rgba(r, g, b, a),Size::new(w, h),.frame(w, h), rect(x, y, w, h).
Scope: the rule binds the app-facing surface (day-pieces, Day umbrella, day-core’s
BuildCx/nav API). Engine seams (the Toolkit trait, TreeOps, FFI shims) prefer the
same, but a documented bool parameter is acceptable where changing it would ripple
through every backend for internal call sites only.