Go to file
Michael Pfaff db01cce71c Refactor and redesign API 2024-03-21 00:34:50 -04:00
examples Adjust formatting 2023-07-03 18:44:28 -04:00
src Refactor and redesign API 2024-03-21 00:34:50 -04:00
.gitignore Where was I? 2022-07-21 20:39:47 -04:00
Cargo.toml Refactor and redesign API 2024-03-21 00:34:50 -04:00
README.md Refactoring, update docs, API adjustments 2023-06-29 01:51:08 -04:00

README.md

How

A seriously contextual error library that focuses on how you got there. Designed to make debugging easier, how enables you to concisely capture any and all context that could possibly have contributed to an error.

Getting started

A basic example takes just 2 imports:

use how::{How, Result};

fn main() -> Result<()> {
	Err(How::new("TODO: implement amazing new program"))
}

But usually you'll want to attach some information too:

use how::{How, Explain, Result};

fn main() -> Result<()> {
	Err(How::new("TODO: implement amazing new program")
        .context("I plan to do it eventually™"))
}

And you'll probably want to get nicer output when you return an error from main (this one requires feature = "termination"):

use how::{How, Explain, Result, TerminationResult};

fn main() -> TerminationResult<()> {
	Err(How::new("TODO: implement amazing new program")
        .context("I plan to do it eventually™"))
        .into()
}

[How] intentionally omits a [From] implementation for Error to discourage the creation of [How]s with no caller context. Instead, the [Explain] trait is implemented for all [Result]1 and [Option] and provides a convenient context function.


  1. Where E is either [How] or implements Error + 'static. ↩︎