Skip to main content

GeneratedCode

Struct GeneratedCode 

Source
#[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
Non-exhaustive structs could have additional fields added in future. Therefore, non-exhaustive structs cannot be constructed in external crates using the traditional 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

Source

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

Source§

fn clone(&self) -> GeneratedCode

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for GeneratedCode

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for GeneratedCode

Source§

fn default() -> GeneratedCode

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.