2 releases

0.1.1 Oct 11, 2024
0.1.0 Oct 11, 2024

#915 in Rust patterns

WTFPL license

7KB
99 lines

Fu

Just an Error with its location and helpful macros.

  • Custom Error type with file name, line, and column information.
  • Short and convenient macros: error!, bail!, and ensure!.
  • Lightweight.

Usage

use fu::{bail, ensure, Result};

const MAX: i32 = 10;

fn example(value: i32) -> Result<()> {
    ensure!(value >= 0, "value must be non-negative");

    if value > MAX {
        bail!("value is larger than {}", MAX);
    }

    Ok(())
}

fn main() -> Result<()> {
    example(-1)
}

// Error: value must be non-negative    examples/foo.rs:[4:5]

lib.rs:

Fu

Just an Error with its location and helpful macros.

  • Custom Error type with file name, line, and column information.
  • Short and convenient macros: error!, bail!, and ensure!.
  • Lightweight.

Usage

use fu::{bail, ensure, Result};

const MAX: i32 = 10;

fn example(value: i32) -> Result<()> {
    ensure!(value >= 0, "value must be non-negative");

    if value > MAX {
        bail!("value is larger than {}", MAX);
    }

    Ok(())
}

fn main() -> Result<()> {
    example(-1)
}

// Error: value must be non-negative    examples/foo.rs:[4:5]

No runtime deps