# Convert Option to Result
[](https://github.com/DenisGorbachev/not-found-error)
[](https://docs.rs/not-found-error)
## Overview
```rust
// Convert Option<i32> to Result<i32, NotFoundError<i32>>
assert_eq!(Some(10).require(), Ok(10));
assert_eq!(None.require(), Err(NotFoundError::<i32>::new()));
```
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`][__link0] function or [`Require`][__link1] extension trait.
You can convert `Option<T>` to `Result<T, NotFoundError<AnotherType>` using [`not_found`][__link2] function or [`OkOrNotFound`][__link3] 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
```rust
use not_found_error::{NotFoundError, require, Require};
// Using the `require` function
let item = require([1, 2, 3].into_iter().next());
assert_eq!(item, Ok(1));
// Using the `require` function
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));
// Using the `require` extension method
let item = [].into_iter().next().require();
assert_eq!(item, Err(NotFoundError::<i32>::new()));
```
[__cargo_doc2readme_dependencies_info]: ggGkYW0BYXSEGyMws-dKI-LpG9swkVXG-rikGwSuJGhB0NVbG974QPrPJF6XYXKEG4uiAprMyl2YGwEqibffC0DYG-1IyG_xaW2ZG8ByAZHP14V5YWSBg29ub3QtZm91bmQtZXJyb3JlMC4xLjJvbm90X2ZvdW5kX2Vycm9y
[__link0]: https://docs.rs/not-found-error/latest/not_found_error/?search=require
[__link1]: https://docs.rs/not-found-error/latest/not_found_error/trait.Require.html
[__link2]: https://docs.rs/not-found-error/latest/not_found_error/?search=not_found
[__link3]: https://docs.rs/not-found-error/latest/not_found_error/trait.OkOrNotFound.html
## Installation
```shell
cargo add not-found-error
```
## Gratitude
Like the project? [Say thanks!](https://github.com/DenisGorbachev/not-found-error/discussions/new) ❤️
## License
[Apache License 2.0](LICENSE-APACHE) or [MIT License](LICENSE-MIT) at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in this crate by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.