Karma3Labs / rs-eigentrust

EigenTrust implementation in Rust
8 stars 4 forks source link

Elide .into_status() methods #33

Closed astralblue closed 8 months ago

astralblue commented 8 months ago

tl;dr ―

impl From<Status> for LcError {
    fn from(value: tonic::Status) -> Self { /* ... */ }
}

Then for functions that return Result<T, tonic::Status>, explicit conversion into status is not needed:

something_that_returns_lc_error_result().map_err(|e| e.into_status())?;
/* is equivalent to a more succinct form of */
something_that_returns_lc_error_result()?;

Full description:

Explicit conversion of LcError into Result<T, Status>::Err for return by the question mark operator can be elided by implementing From<LcError> for Status, thanks to the question mark operator being able to accept not just Err<Status> but Err<impl Into<Status>>, which is automatically provided by the implementation of From<LcError> for Status.

Same deal for AttTrError.