Add IntoBinderResult trait to simplify binder error handling
Before this change, returning binder::Result<T> was a bit cumbersome,
and the integration with anyhow was not nice:
```
use anyhow::{Context, Result};
fn file_exists(name: &str) -> binder::Result<bool> {
std::fs::metadata(name)
.with_context("cannot find {}")
.map_err(|e| {
Status::new_service_specific_err_str(
NOT_FOUND,
Some("{:?}", e)
)
})?
}
```
With this change, above can be simplified as below:
```
use binder::IntoBinderResult;
use anyhow::{Context, Result};
fn file_exists(name: &str) -> binder::Result<bool> {
std::fs::metadata(name)
.with_context("cannot find {}", name)
.or_service_specific_exception(NOT_FOUND)?
}
```
Bug: 294348831
Test: atest libbinder_rs-internal_test
Change-Id: I4c669ac39c01f648f68ecf6db7e088edec034825
diff --git a/libs/binder/rust/src/lib.rs b/libs/binder/rust/src/lib.rs
index 0c8b48f..8841fe6 100644
--- a/libs/binder/rust/src/lib.rs
+++ b/libs/binder/rust/src/lib.rs
@@ -106,7 +106,7 @@
pub use crate::binder_async::{BinderAsyncPool, BoxFuture};
pub use binder::{BinderFeatures, FromIBinder, IBinder, Interface, Strong, Weak};
-pub use error::{ExceptionCode, Status, StatusCode};
+pub use error::{ExceptionCode, IntoBinderResult, Status, StatusCode};
pub use native::{
add_service, force_lazy_services_persist, is_handling_transaction, register_lazy_service,
LazyServiceGuard,