fix(sdk): without phantom data

This commit is contained in:
Kasper Juul Hermansen 2023-02-19 17:29:59 +01:00
parent c14cd64453
commit b25b350d90
Signed by: kjuulh
GPG Key ID: 57B6E1465221F912
7 changed files with 28 additions and 23 deletions

View File

@ -28,7 +28,7 @@ fn main() -> eyre::Result<()> {
}
}
fn release(client: Arc<Query>, subm: &clap::ArgMatches) -> Result<(), color_eyre::Report> {
fn release(client: Arc<Query>, _subm: &clap::ArgMatches) -> Result<(), color_eyre::Report> {
let src_dir = client.host().directory(
".".into(),
Some(HostDirectoryOpts {

View File

@ -1,6 +1,7 @@
use dagger_core::introspection::{FullType, FullTypeFields, FullTypeFieldsArgs};
use genco::prelude::rust;
use genco::quote;
use itertools::Itertools;
use crate::functions::{type_ref_is_optional, CommonFunctions};
use crate::rust::functions::{
@ -64,10 +65,10 @@ fn render_optional_arg(funcs: &CommonFunctions, field: &FullTypeFields) -> Optio
let builder = rust::import("derive_builder", "Builder");
let phantom_data = rust::import("std::marker", "PhantomData");
if let Some(fields) = fields {
if let Some((fields, contains_lifetime)) = fields {
Some(quote! {
#[derive($builder, Debug, PartialEq)]
pub struct $output_type<'a> {
pub struct $output_type$(if contains_lifetime => <'a>) {
//#[builder(default, setter(skip))]
//pub marker: $(phantom_data)<&'a ()>,
$fields
@ -81,20 +82,28 @@ fn render_optional_arg(funcs: &CommonFunctions, field: &FullTypeFields) -> Optio
fn render_optional_field_args(
funcs: &CommonFunctions,
args: &Vec<&FullTypeFieldsArgs>,
) -> Option<rust::Tokens> {
) -> Option<(rust::Tokens, bool)> {
if args.len() == 0 {
return None;
}
let mut contains_lifetime = false;
let rendered_args = args.into_iter().map(|a| &a.input_value).map(|a| {
let type_ = funcs.format_immutable_input_type(&a.type_);
if type_.contains("str") {
contains_lifetime = true;
}
quote! {
#[builder(setter(into, strip_option))]
pub $(format_struct_name(&a.name)): Option<$(funcs.format_immutable_input_type(&a.type_))>,
pub $(format_struct_name(&a.name)): Option<$(type_)>,
}
});
Some(quote! {
Some((
quote! {
$(for arg in rendered_args join ($['\r']) => $arg)
})
},
contains_lifetime,
))
}
fn render_functions(funcs: &CommonFunctions, fields: &Vec<FullTypeFields>) -> Option<rust::Tokens> {

View File

@ -8,7 +8,6 @@ fn main() -> eyre::Result<()> {
Some(HostDirectoryOpts {
exclude: Some(vec!["node_modules".into(), "ci/".into()]),
include: None,
marker: std::marker::PhantomData,
}),
);

View File

@ -9,7 +9,6 @@ fn main() -> eyre::Result<()> {
Some(HostDirectoryOpts {
exclude: Some(vec!["node_modules", "ci/"]),
include: None,
marker: std::marker::PhantomData,
}),
);

View File

@ -10,7 +10,6 @@ fn main() -> eyre::Result<()> {
Some(HostDirectoryOpts {
exclude: Some(vec!["node_modules", "ci/"]),
include: None,
marker: std::marker::PhantomData,
}),
);

View File

@ -8,7 +8,6 @@ fn main() -> eyre::Result<()> {
Some(HostDirectoryOpts {
exclude: Some(vec!["node_modules", "ci/"]),
include: None,
marker: std::marker::PhantomData,
}),
);

View File

@ -67,7 +67,7 @@ pub struct ContainerExecOpts<'a> {
pub experimental_privileged_nesting: Option<bool>,
}
#[derive(Builder, Debug, PartialEq)]
pub struct ContainerExportOpts<'a> {
pub struct ContainerExportOpts {
#[builder(setter(into, strip_option))]
pub platform_variants: Option<Vec<ContainerId>>,
}
@ -77,7 +77,7 @@ pub struct ContainerPipelineOpts<'a> {
pub description: Option<&'a str>,
}
#[derive(Builder, Debug, PartialEq)]
pub struct ContainerPublishOpts<'a> {
pub struct ContainerPublishOpts {
#[builder(setter(into, strip_option))]
pub platform_variants: Option<Vec<ContainerId>>,
}
@ -105,12 +105,12 @@ pub struct ContainerWithExecOpts<'a> {
pub experimental_privileged_nesting: Option<bool>,
}
#[derive(Builder, Debug, PartialEq)]
pub struct ContainerWithFileOpts<'a> {
pub struct ContainerWithFileOpts {
#[builder(setter(into, strip_option))]
pub permissions: Option<isize>,
}
#[derive(Builder, Debug, PartialEq)]
pub struct ContainerWithMountedCacheOpts<'a> {
pub struct ContainerWithMountedCacheOpts {
#[builder(setter(into, strip_option))]
pub source: Option<DirectoryId>,
#[builder(setter(into, strip_option))]
@ -777,17 +777,17 @@ pub struct DirectoryWithDirectoryOpts<'a> {
pub include: Option<Vec<&'a str>>,
}
#[derive(Builder, Debug, PartialEq)]
pub struct DirectoryWithFileOpts<'a> {
pub struct DirectoryWithFileOpts {
#[builder(setter(into, strip_option))]
pub permissions: Option<isize>,
}
#[derive(Builder, Debug, PartialEq)]
pub struct DirectoryWithNewDirectoryOpts<'a> {
pub struct DirectoryWithNewDirectoryOpts {
#[builder(setter(into, strip_option))]
pub permissions: Option<isize>,
}
#[derive(Builder, Debug, PartialEq)]
pub struct DirectoryWithNewFileOpts<'a> {
pub struct DirectoryWithNewFileOpts {
#[builder(setter(into, strip_option))]
pub permissions: Option<isize>,
}
@ -1360,19 +1360,19 @@ pub struct Query {
}
#[derive(Builder, Debug, PartialEq)]
pub struct QueryContainerOpts<'a> {
pub struct QueryContainerOpts {
#[builder(setter(into, strip_option))]
pub id: Option<ContainerId>,
#[builder(setter(into, strip_option))]
pub platform: Option<Platform>,
}
#[derive(Builder, Debug, PartialEq)]
pub struct QueryDirectoryOpts<'a> {
pub struct QueryDirectoryOpts {
#[builder(setter(into, strip_option))]
pub id: Option<DirectoryId>,
}
#[derive(Builder, Debug, PartialEq)]
pub struct QueryGitOpts<'a> {
pub struct QueryGitOpts {
#[builder(setter(into, strip_option))]
pub keep_git_dir: Option<bool>,
}
@ -1382,7 +1382,7 @@ pub struct QueryPipelineOpts<'a> {
pub description: Option<&'a str>,
}
#[derive(Builder, Debug, PartialEq)]
pub struct QuerySocketOpts<'a> {
pub struct QuerySocketOpts {
#[builder(setter(into, strip_option))]
pub id: Option<SocketId>,
}