Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit e731c490 authored by Jiyong Park's avatar Jiyong Park
Browse files

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
parent ada46f8b
Loading
Loading
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment