Skip to content

Commit 380b9ef

Browse files
committed
Remove an unneeded exported macro
Instead, expand the match directly in `expand.rs` to minimize the public API.
1 parent 3714d23 commit 380b9ef

File tree

2 files changed

+11
-16
lines changed

2 files changed

+11
-16
lines changed

macro/src/expand.rs

+11-3
Original file line numberDiff line numberDiff line change
@@ -1109,7 +1109,15 @@ fn expand_rust_function_shim_impl(
11091109
None => quote_spanned!(span=> &mut ()),
11101110
};
11111111
requires_closure = true;
1112-
expr = quote_spanned!(span=> ::cxx::map_rust_result_to_cxx_result!(#out, #expr));
1112+
expr = quote_spanned!(span=>
1113+
match #expr {
1114+
Ok(ok) => {
1115+
::core::ptr::write(#out, ok);
1116+
::cxx::private::CxxResult::new()
1117+
}
1118+
Err(err) => ::cxx::private::CxxResult::from(err),
1119+
}
1120+
);
11131121
} else if indirect_return {
11141122
requires_closure = true;
11151123
expr = quote_spanned!(span=> ::cxx::core::ptr::write(__return, #expr));
@@ -1193,10 +1201,10 @@ fn expand_rust_function_shim_super(
11931201
// Set spans that result in the `Result<...>` written by the user being
11941202
// highlighted as the cause if their error type is not convertible to
11951203
// CxxException (i.e., no `Display` trait by default).
1196-
let result_begin = quote_spanned!{ result.span=>
1204+
let result_begin = quote_spanned! { result.span=>
11971205
|e| ::cxx::map_rust_error_to_cxx_exception!
11981206
};
1199-
let result_end = quote_spanned!{ rangle.span=> (e) };
1207+
let result_end = quote_spanned! { rangle.span=> (e) };
12001208
quote_spanned! {span=>
12011209
#call(#(#vars,)*).map_err( #result_begin #result_end )
12021210
}

src/result.rs

-13
Original file line numberDiff line numberDiff line change
@@ -240,16 +240,3 @@ macro_rules! map_rust_error_to_cxx_exception {
240240
exc
241241
}};
242242
}
243-
244-
#[macro_export]
245-
macro_rules! map_rust_result_to_cxx_result {
246-
($ret_ptr:expr, $result:expr) => {
247-
match $result {
248-
Ok(ok) => {
249-
unsafe { ::core::ptr::write($ret_ptr, ok) };
250-
$crate::private::CxxResult::new()
251-
}
252-
Err(err) => $crate::private::CxxResult::from(err),
253-
}
254-
};
255-
}

0 commit comments

Comments
 (0)