Skip to content

Commit

Permalink
Remove an unneeded exported macro
Browse files Browse the repository at this point in the history
Instead, expand the match directly in `expand.rs` to minimize the
public API.
  • Loading branch information
schreter committed Feb 28, 2023
1 parent 3714d23 commit 380b9ef
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 16 deletions.
14 changes: 11 additions & 3 deletions macro/src/expand.rs
Expand Up @@ -1109,7 +1109,15 @@ fn expand_rust_function_shim_impl(
None => quote_spanned!(span=> &mut ()),
};
requires_closure = true;
expr = quote_spanned!(span=> ::cxx::map_rust_result_to_cxx_result!(#out, #expr));
expr = quote_spanned!(span=>
match #expr {
Ok(ok) => {
::core::ptr::write(#out, ok);
::cxx::private::CxxResult::new()
}
Err(err) => ::cxx::private::CxxResult::from(err),
}
);
} else if indirect_return {
requires_closure = true;
expr = quote_spanned!(span=> ::cxx::core::ptr::write(__return, #expr));
Expand Down Expand Up @@ -1193,10 +1201,10 @@ fn expand_rust_function_shim_super(
// Set spans that result in the `Result<...>` written by the user being
// highlighted as the cause if their error type is not convertible to
// CxxException (i.e., no `Display` trait by default).
let result_begin = quote_spanned!{ result.span=>
let result_begin = quote_spanned! { result.span=>
|e| ::cxx::map_rust_error_to_cxx_exception!
};
let result_end = quote_spanned!{ rangle.span=> (e) };
let result_end = quote_spanned! { rangle.span=> (e) };
quote_spanned! {span=>
#call(#(#vars,)*).map_err( #result_begin #result_end )
}
Expand Down
13 changes: 0 additions & 13 deletions src/result.rs
Expand Up @@ -240,16 +240,3 @@ macro_rules! map_rust_error_to_cxx_exception {
exc
}};
}

#[macro_export]
macro_rules! map_rust_result_to_cxx_result {
($ret_ptr:expr, $result:expr) => {
match $result {
Ok(ok) => {
unsafe { ::core::ptr::write($ret_ptr, ok) };
$crate::private::CxxResult::new()
}
Err(err) => $crate::private::CxxResult::from(err),
}
};
}

0 comments on commit 380b9ef

Please sign in to comment.