crate::ix!();
pub fn generate_impl_send_sync(parsed: &LmbwParsedInput) -> TokenStream2 {
trace!("generate_impl_send_sync: start.");
let struct_ident = parsed.struct_ident();
let (impl_generics, ty_generics, where_clause) = parsed.generics().split_for_impl();
quote! {
unsafe impl #impl_generics Send for #struct_ident #ty_generics #where_clause {}
unsafe impl #impl_generics Sync for #struct_ident #ty_generics #where_clause {}
}
}
#[cfg(test)]
mod test_generate_impl_send_sync {
use super::*;
#[traced_test]
fn generates_send_sync() {
info!("Starting generates_send_sync test.");
let parsed = LmbwParsedInputBuilder::default()
.struct_ident::<syn::Ident>(parse_quote! { Dummy })
.generics(syn::Generics::default())
.batch_client_field(Some(parse_quote! { some_client }))
.batch_workspace_field(Some(parse_quote! { some_workspace }))
.model_type_field(Some(parse_quote! { mt }))
.custom_error_type(Some(parse_quote! { MyCustomError }))
.build()
.unwrap();
let tokens = generate_impl_send_sync(&parsed);
let code = tokens.to_string();
info!("Generated code: {}", code);
assert!(code.contains("unsafe impl Send for Dummy"), "Should declare unsafe impl Send for Dummy.");
assert!(code.contains("unsafe impl Sync for Dummy"), "Should declare unsafe impl Sync for Dummy.");
}
}