Skip to content

Commit

Permalink
use cow instead of &'static to better support testing use cases
Browse files Browse the repository at this point in the history
  • Loading branch information
kurtbuilds committed Jan 1, 2024
1 parent 124645a commit 5acdf6d
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
1 change: 1 addition & 0 deletions core/template/rust/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ pub mod model;
pub mod request;
pub use httpclient::{Error, Result, InMemoryResponseExt};
use std::sync::{Arc, OnceLock};
use std::borrow::Cow;
use crate::model::*;
4 changes: 2 additions & 2 deletions libninja/src/rust.rs
Original file line number Diff line number Diff line change
Expand Up @@ -253,8 +253,8 @@ fn static_shared_http_client(spec: &HirSpec, opt: &PackageConfig) -> TokenStream
let _ = SHARED_HTTPCLIENT.set(init);
}

fn shared_http_client() -> &'static httpclient::Client {
SHARED_HTTPCLIENT.get_or_init(default_http_client)
fn shared_http_client() -> Cow<'static, httpclient::Client> {
Cow::Borrowed(SHARED_HTTPCLIENT.get_or_init(default_http_client))
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions libninja/src/rust/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ fn build_Client_new_with(spec: &HirSpec, opt: &PackageConfig) -> Function<TokenS
let auth_struct = opt.authenticator_name().to_rust_struct();
let body = quote! {
Self {
client,
client: Cow::Owned(client),
authentication,
}
};
Expand All @@ -94,7 +94,7 @@ fn build_Client_new_with(spec: &HirSpec, opt: &PackageConfig) -> Function<TokenS
body,
args: vec![FnArg {
name: ArgIdent::Ident("client".to_string()),
ty: quote!(&'static httpclient::Client),
ty: quote!(httpclient::Client),
default: None,
treatment: None,
}, FnArg {
Expand All @@ -113,7 +113,7 @@ pub fn struct_Client(spec: &HirSpec, opt: &PackageConfig) -> Class<TokenStream>
let mut instance_fields = vec![
Field {
name: "client".to_string(),
ty: quote!(&'static httpclient::Client),
ty: quote!(Cow<'static, httpclient::Client>),
..Field::default()
}
];
Expand Down

0 comments on commit 5acdf6d

Please sign in to comment.