Crate not_found_error

source ·
Expand description

§Overview

This crate provides a generic NotFoundError<T> type and associated utilities for handling “not found” scenarios in a type-safe and ergonomic manner.

You can convert Option<T> to Result<T, NotFoundError<T> using require function or Require extension trait.

You can convert Option<T> to Result<T, NotFoundError<AnotherType> using not_found function or OkOrNotFound extension trait.

§Features

[x] Generic NotFoundError<T> type [x] Conversion functions and traits to transform Option<T> into Result<T, NotFoundError<T>> [x] Conversion functions and traits to transform Option<T> into Result<T, NotFoundError<AnotherType>>

§Examples

use not_found_error::{NotFoundError, require, Require};

let item = require([1, 2, 3].into_iter().next());
assert_eq!(item, Ok(1));

let item = require([].into_iter().next());
assert_eq!(item, Err(NotFoundError::<i32>::new()));

// Using the `require` extension method
let item = [1, 2, 3].into_iter().next().require();
assert_eq!(item, Ok(1));

let item = [].into_iter().next().require();
assert_eq!(item, Err(NotFoundError::<i32>::new()));

Structs§

  • Represents an error indicating that a value was not found.

Traits§

  • An extension trait for Option<T> to convert it to Result<T, NotFoundError<AnotherType>>
  • An extension trait for Option<T> to convert it to Result<T, NotFoundError<T>>

Functions§

  • A shorter version of NotFoundError::new().
  • Converts Option<T> to Result<T, NotFoundError<T>>