pub(super) fn bridged_call(call: &str, throws: bool, is_async: bool) -> String {
match (throws, is_async) {
(true, true) => format!("try await alefBridgedCallAsync {{ try await {call} }}"),
(true, false) => format!("try alefBridgedCall {{ try {call} }}"),
(false, true) => format!("await {call}"),
(false, false) => call.to_string(),
}
}
#[cfg(test)]
mod tests {
use super::bridged_call;
#[test]
fn a_throwing_call_goes_through_the_conversion() {
assert_eq!(
bridged_call("RustBridge.f(x)", true, false),
"try alefBridgedCall { try RustBridge.f(x) }"
);
assert_eq!(
bridged_call("RustBridge.f(x)", true, true),
"try await alefBridgedCallAsync { try await RustBridge.f(x) }"
);
}
#[test]
fn a_call_that_cannot_fail_stays_plain() {
assert_eq!(bridged_call("RustBridge.f(x)", false, false), "RustBridge.f(x)");
assert_eq!(bridged_call("RustBridge.f(x)", false, true), "await RustBridge.f(x)");
}
}