Skip to content

Commit

Permalink
add new_with method
Browse files Browse the repository at this point in the history
  • Loading branch information
kurtbuilds committed Jan 1, 2024
1 parent 7707289 commit f183b03
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions libninja/src/rust/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,34 @@ fn build_Client_with_auth(spec: &HirSpec, opt: &PackageConfig) -> Function<Token
}
}

fn build_Client_new_with(spec: &HirSpec, opt: &PackageConfig) -> Function<TokenStream> {
let auth_struct = opt.authenticator_name().to_rust_struct();
let body = quote! {
Self {
client
authentication
}
};
Function {
name: Ident::new("new_with"),
public: true,
ret: quote!(Self),
body,
args: vec![FnArg {
name: ArgIdent::Ident("client".to_string()),
ty: quote!(&'static httpclient::Client),
default: None,
treatment: None,
}, FnArg {
name: ArgIdent::Ident("authentication".to_string()),
ty: quote!(#auth_struct),
default: None,
treatment: None,
}],
..Function::default()
}
}

pub fn struct_Client(spec: &HirSpec, opt: &PackageConfig) -> Class<TokenStream> {
let auth_struct_name = opt.authenticator_name().to_rust_struct();

Expand Down Expand Up @@ -115,6 +143,7 @@ pub fn struct_Client(spec: &HirSpec, opt: &PackageConfig) -> Class<TokenStream>
..Function::default()
});
}
class_methods.push(build_Client_new_with(spec, opt));
Class {
name: opt.client_name().to_rust_struct(),
instance_fields,
Expand Down

0 comments on commit f183b03

Please sign in to comment.