Repository navigation
Conversation
Characterizes what the hand-written impls produce so the next commit can replace them without changing the wire format.
nutype replaces the hand-written Display, serde and sqlx impls; sqlx's transparent derive is forwarded through derive_unchecked. ToSchema stays hand-written because the derive would add the doc comment to the OpenAPI schema as a description. The previous commit's tests pin the wire format, and pass unchanged. MACRO-4999
|
Note Some coding-guideline sources were skipped or only partly applied; the reason is listed next to each one. On a public repository, this repository's guideline files are counted without their names. Skipped guideline sources
No actionable comments were generated in the recent review. Summary
Merge Risk:
|
|
Folded into the single reorg PR #10111 (one PR for the whole reorganization). Its commits are there; closing this one. |
Why
The reorganization plan adds a crate per entity id (
document_id,channel_id, …) and replaces four hand-rolled id macros. Before writing adozen of them, this checks on one real id whether
nutype(already aworkspace dependency) can replace the hand-written trait impls without
changing anything on the wire: Postgres encoding, OpenAPI schema, and serde.
harness_idis the test subject because it has every impl by hand.MACRO-4999
How it works
The first commit pins today's behaviour in tests, run green against the
hand-written impls:
HarnessIdand serializes to exactly{"type":"string"}.type_info,compatibleand the array type equalUuid's, andthe encoded bytes equal the UUID's 16 bytes.
The second commit rewrites
HarnessIdas a#[nutype]withconst_fnandderive(Debug, Clone, Copy, PartialEq, Eq, Hash, Display, Serialize, Deserialize), plusderive_unchecked(sqlx::Type)with#[sqlx(transparent)]behind thesqlxfeature. The public API(
new_from_uuid,as_uuid,parse_uuid_str,TEST_A/TEST_B, theFromStrerror) is unchanged. All 6 tests pass.Findings
#[sqlx(transparent)]to thederive_unchecked(sqlx::Type)derive, which replaces the four hand-writtenimpls (
Type,PgHasArrayType,Encode,Decode). Theharnesses,macro_authorizationandbotsDB tests round-tripHarnessIdthroughreal Postgres queries and pass.
Serialize/Deserializeare transparent.derive_unchecked(utoipa::ToSchema)copies the doc comment into the schemaas a
description. The new characterization test caught that this wouldchange the published OpenAPI. Ids whose schema already comes from
#[derive(utoipa::ToSchema)](thedatabase_id!/form_id!macros) carrythat description today, so for them the derive is a no-op change.
FromStr: hand-written when the error type matters. nutype'sderive(FromStr)wraps the inner type's parse error in a generated enum.Ids with their own error type, like
HarnessIdParseError, keep athree-line impl.
harness_idhas none). The id macros PRchecks it on the
models_databasesandmodels_formsids, whosegenerated TypeScript is checked in.
Verdict: use nutype for new id crates. Hand-write
ToSchemaonly where thecurrent schema has no description, and
FromStronly where an id has its ownerror type.