mirror of
https://github.com/kjuulh/dagger-rs.git
synced 2025-08-18 13:03:28 +02:00
feature/add impl (#6)
* format code * with object gen and args * add implementation * add rust generator * reset generated code * add basic output * reset output * add object * add format function * with opts * fix vec * add context to unwrap * fix arguments * with function body * first complete generation: Still missing Vec<Obj> * run full alpine * add roadmap item
This commit is contained in:
38
crates/dagger-codegen/src/rust/templates/input_tmpl.rs
Normal file
38
crates/dagger-codegen/src/rust/templates/input_tmpl.rs
Normal file
@@ -0,0 +1,38 @@
|
||||
use dagger_core::introspection::{FullType, FullTypeInputFields};
|
||||
use genco::prelude::rust;
|
||||
use genco::quote;
|
||||
|
||||
use crate::functions::CommonFunctions;
|
||||
use crate::rust::functions::{format_name, format_struct_name};
|
||||
|
||||
pub fn render_input(funcs: &CommonFunctions, t: &FullType) -> eyre::Result<rust::Tokens> {
|
||||
let deserialize = rust::import("serde", "Deserialize");
|
||||
let serialize = rust::import("serde", "Serialize");
|
||||
Ok(quote! {
|
||||
#[derive($serialize, $deserialize)]
|
||||
pub struct $(format_name(t.name.as_ref().unwrap())) {
|
||||
$(render_input_fields(funcs, t.input_fields.as_ref().unwrap_or(&Vec::new()) ))
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
pub fn render_input_fields(
|
||||
funcs: &CommonFunctions,
|
||||
fields: &[FullTypeInputFields],
|
||||
) -> Option<rust::Tokens> {
|
||||
let rendered_fields = fields.iter().map(|f| render_input_field(funcs, f));
|
||||
|
||||
if rendered_fields.len() == 0 {
|
||||
None
|
||||
} else {
|
||||
Some(quote! {
|
||||
$(for field in rendered_fields join ($['\r']) => $field)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
pub fn render_input_field(funcs: &CommonFunctions, field: &FullTypeInputFields) -> rust::Tokens {
|
||||
quote! {
|
||||
pub $(format_struct_name(&field.input_value.name)): $(funcs.format_input_type(&field.input_value.type_)),
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user