Skip to content

Commit

Permalink
bindgen
Browse files Browse the repository at this point in the history
  • Loading branch information
kennykerr committed Jan 16, 2025
1 parent e99e11c commit 6bab320
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 17 deletions.
8 changes: 1 addition & 7 deletions crates/libs/bindgen/src/types/cpp_fn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,13 +144,7 @@ impl CppFn {
ReturnHint::ResultValue => {
let where_clause = method.write_where(writer, false);
let return_type = signature.params[signature.params.len() - 1].0.deref();

let map = if !return_type.is_interface() {
quote! { map(||core::mem::transmute(result__)) }
} else {
quote! { and_then(||windows_core::Type::from_abi(result__)) }
};

let map = return_type.write_result_map();
let return_type = return_type.write_name(writer);

quote! {
Expand Down
9 changes: 1 addition & 8 deletions crates/libs/bindgen/src/types/cpp_method.rs
Original file line number Diff line number Diff line change
Expand Up @@ -311,14 +311,7 @@ impl CppMethod {
.0
.deref();

let map = if return_type.is_copyable() {
quote! { map(||result__) }
} else if return_type.is_interface() {
quote! { and_then(||windows_core::Type::from_abi(result__)) }
} else {
quote! { map(||core::mem::transmute(result__)) }
};

let map = return_type.write_result_map();
let return_type = return_type.write_name(writer);

quote! {
Expand Down
12 changes: 10 additions & 2 deletions crates/libs/bindgen/src/types/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -860,9 +860,7 @@ impl Type {
_ => self.clone(),
}
}
}

impl Type {
fn write_no_deps(&self, writer: &Writer) -> TokenStream {
if !writer.config.no_core {
return quote! {};
Expand Down Expand Up @@ -991,6 +989,16 @@ impl Type {
| Self::String
)
}

pub fn write_result_map(&self) -> TokenStream {
if self.is_copyable() {
quote! { map(||result__) }
} else if self.is_interface() {
quote! { and_then(||windows_core::Type::from_abi(result__)) }
} else {
quote! { map(||core::mem::transmute(result__)) }
}
}
}

pub fn interface_signature(def: TypeDef, generics: &[Type]) -> String {
Expand Down

0 comments on commit 6bab320

Please sign in to comment.