Skip to main content

Module embed_struct_optional

Module embed_struct_optional 

Source
Expand description

Option<StructEmbed> model fields.

A nullable embedded struct stores a nullable bool presence column (NULL = None, true = Some) plus its flattened leaf columns forced nullable. None is NULL in the presence column, symmetric with Option<scalar> and an embedded enum’s discriminant. This disambiguates None from a Some whose fields happen to all be empty.

A single-column embed (a newtype Option<Code> where Code(String)) is the exception: its one flattened leaf already collapses to the field name, so it reuses that leaf as the head column (NULL = None) instead of a dedicated presence column that would collide with it — exactly like Option<scalar>.

Functions§

option_embed_create_ops
Driver-op coverage for create. A Some writes true to the presence column plus the leaf values; a None writes NULL to the presence column and every leaf column. The column set is identical in both cases — None is a concrete all-NULL row, not an omitted/absent one.
option_embed_crud
Round-trip both Some and None.
option_embed_db_schema
The DB schema: a nullable bool presence column named after the field, plus one nullable column per flattened leaf field.
option_embed_filter_eq
Whole-value .eq(Some(..)) matches only the equal Some row, never None.
option_embed_filter_ops
Driver-op coverage for filters. .is_none() / .is_some() emit a predicate on the single presence column (IS NULL / NOT (.. IS NULL)), never a check distributed across the leaf columns.
option_embed_filter_presence
.is_none() / .is_some() filter on the presence column.
option_embed_update
Updating the whole value in both directions: SomeNone and NoneSome.
option_embed_update_ops
Driver-op coverage for updates. Setting Some assigns true + the leaf values; setting None assigns NULL to the presence column and every leaf.
option_newtype_create_ops
Driver-op coverage. Some writes the inner value to the single code column; None writes NULL to it. There is no separate presence column.
option_newtype_crud
Round-trip both Some and None.
option_newtype_db_schema
The DB schema: exactly one nullable column named after the field, with no separate presence column.
option_newtype_filter_eq
Whole-value .eq(Some(..)) on the reused head column matches only the equal Some row, never None.
option_newtype_filter_ops
Driver-op coverage for filters: .is_none() emits code IS NULL on the single reused column.
option_newtype_filter_presence
.is_none() / .is_some() filter on the reused head (the single leaf) column.
option_newtype_update
Updating the whole value in both directions: SomeNone and NoneSome.
option_newtype_wrapping_option_rejected
Option<Newtype> where the newtype wraps an Option (MaybeBody(Option<String>)) has no unambiguous single-column mapping — the one column can’t tell None from Some(MaybeBody(None)), and a dedicated presence column would collide with the newtype leaf. It is rejected at schema build rather than silently collapsing Some(None) to None.
option_struct_nullable_inner_disambiguates
Contrast with the rejected newtype above: a named single field whose inner is itself nullable (Wrapper { value: Option<String> }) keeps the dedicated presence column, so it round-trips Some(value: None) distinctly from None — the disambiguation a single reused column can’t provide.