Skip to main content

ConnectOptionExt

Trait ConnectOptionExt 

Source
pub trait ConnectOptionExt<T>: Sealed {
    // Required method
    fn or_not_found(self, msg: &str) -> Result<T, ConnectError>
       where Self: Sized;
}
Expand description

Extension trait on Result<Option<T>, E> for ergonomic not-found shaping.

Sealed — only api-bones provides an implementation. Reimplementing in service code produces a different trait that will not satisfy imports using this path, making the canonical combinator mandatory at call sites that import it (ADR-0096 §Enforcement Level 1).

§Example

use api_bones::connect::ConnectOptionExt as _;
use connectrpc::ConnectError;

async fn get_record(id: u64) -> Result<String, ConnectError> {
    let row: Option<String> = None; // e.g. from a DB lookup
    Ok(Ok::<_, ConnectError>(row).or_not_found("record not found")?)
}

Required Methods§

Source

fn or_not_found(self, msg: &str) -> Result<T, ConnectError>
where Self: Sized,

Return ConnectError::not_found(msg) if the inner value is None, or propagate the Err variant mapped through Into<ConnectError>.

§Errors

Returns Err(ConnectError::not_found(msg)) when self is Ok(None). Returns Err(e.into()) when self is Err(e).

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl<T, E> ConnectOptionExt<T> for Result<Option<T>, E>
where E: Into<ConnectError>,

Implementors§