#[non_exhaustive]pub struct GeneratedCode {
pub query_fn: Option<String>,
pub row_struct: Option<String>,
pub model_struct: Option<String>,
pub enum_def: Option<String>,
pub nested_struct_defs: Vec<NestedStructDef>,
pub degraded_nested_structs: Vec<NestedStructDegradation>,
}Fields (Non-exhaustive)§
This struct is marked as non-exhaustive
Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.query_fn: Option<String>§row_struct: Option<String>§model_struct: Option<String>§enum_def: Option<String>§nested_struct_defs: Vec<NestedStructDef>Nested-aggregate struct definitions this query needs, one entry per
scythe_core::analyzer::NestedStructInfo the backend opted into.
Kept out of model_struct (where composites go) because these have
to be deduplicated across the queries written into one file: two
queries can legitimately derive the same struct name, and emitting
the definition twice is E0428 in Rust and a redeclaration in every
other target. model_struct is already a rendered blob with no
identity attached, so the name has to survive alongside the code for
the writer to dedupe on. See scythe-cli’s generate_for_backend.
degraded_nested_structs: Vec<NestedStructDegradation>One entry per column degrade_unsupported_nested_structs rewrote
because backend did not opt the referenced struct into
CodegenBackend::generate_nested_struct_def (GH #147).
Populated even though the rewrite itself is not an error. Counting by
all 102 manifests overstates the reach: catalog_has_nested_aggregates
(scythe-core, analyzer/expressions.rs) only infers a nested
aggregate for the PostgreSQL dialect on a postgresql-family engine –
Redshift and DuckDB are excluded by name even though SqlDialect
maps them onto PostgreSQL – so only the 19 postgresql-engine
manifests can reach this code at all. Of those, 4 build a real struct
(generate_nested_struct_def), 9 keep the array shape via
json_array (including ruby-pg, as of GH #147’s fix – its
ruby_coercion now genuinely decodes JSON, so the json_array
marker is honest there too), and 6 collapse to plain json:
csharp-npgsql, java-jdbc, java-r2dbc, kotlin-exposed, kotlin-jdbc and
kotlin-r2dbc. Failing those 6 by default would break working setups.
But the rewrite is a
silent narrowing (a structured row collapses to an opaque JSON
string or array scalar a caller must parse itself), and before this
field existed nothing told the caller it happened at all: scythe generate exited 0 either way. A caller (scythe-cli) is expected to
turn each entry into a reported finding; see
degrade_unsupported_nested_structs’s doc comment for exactly what
each field means.
Implementations§
Source§impl GeneratedCode
impl GeneratedCode
Sourcepub fn build(init: impl FnOnce(&mut Self)) -> Self
pub fn build(init: impl FnOnce(&mut Self)) -> Self
Build a GeneratedCode from Default, assigning fields inside
init.
#[non_exhaustive] forbids a struct literal outside this crate –
including with ..Default::default() – so downstream crates
(scythe-cli, and anyone embedding the generator) have no other way
to construct one. Mirrors
scythe_core::analyzer::AnalyzedQuery::build, and keeping
construction a single expression avoids clippy’s
field_reassign_with_default.
use scythe_codegen::GeneratedCode;
let code = GeneratedCode::build(|c| {
c.query_fn = Some("fn get_user() {}".to_string());
});
assert!(code.row_struct.is_none());Trait Implementations§
Source§impl Clone for GeneratedCode
impl Clone for GeneratedCode
Source§fn clone(&self) -> GeneratedCode
fn clone(&self) -> GeneratedCode
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more