Extension to `thiserror` that helps reduce the amount of handwriting

Overview

justerror

This macro piggybacks on thiserror crate and is supposed to reduce the amount of handwriting when you want errors in your app to be described via explicit types (rather than anyhow).

Installation

Add to Cargo.toml:

justerror = "0.1"

Add to main.rs:

#[macro_use]
extern crate justerror;

Usage

This macro takes a subject struct or enum and applies thiserror attributes with predefined #[error] messages.

Generally, you can attach #[Error] macro to an error type and be done with it.

#[Error]
enum EnumError {
  Foo,
  Bar {
    a: &'static str,
    b: usize
  },
}

eprintln!("{}", EnumError::Bar { a: "Hey!", b: 42 });

// EnumError::Bar
// === DEBUG DATA:
// a: Hey!
// b: 42

Macro accepts two optional arguments:

  • desc: string
  • fmt: display | debug | "<custom format>"

Both can be applied at the root level.

#[Error(desc = "My emum error description", fmt = debug)]
enum EnumError {
  Foo(usize),
}

And at the variant level.

#[Error(desc = "My emum error description", fmt = debug)]
enum EnumError {
  #[error(desc = "Foo error description", fmt = display)]
  Foo(usize),
}

fmt can also be applied to individual fields.

#[Error(desc = "My emum error description", fmt = debug)]
enum EnumError {
  #[error(desc = "Foo error description", fmt = display)]
  Foo(#[fmt(">5")] usize),
}

See tests for more examples.

License

MIT.

You might also like...
Tiny CLI tool that helps to visualize iCal file content in the terminal.
Tiny CLI tool that helps to visualize iCal file content in the terminal.

Calio Calio is a tiny CLI tool that helps to visualize iCal file in the terminal. Installation You can either install it via cargo or download the bin

A Turing-complete but dead-simple spaced repetition CLI that helps you learn stuff.

Forne — Learn Stuff Forne is a Turing-complete spaced repetition engine to help you learn stuff your way. What does that mean? Well, there are a few p

Mafa is a command-line tool that helps people interact with online websites in a terminal(tty).
Mafa is a command-line tool that helps people interact with online websites in a terminal(tty).

Table of Contents A Small Demo Installation Prerequisite Option 1: Cargo install (recommended) Option 2: Build from source Option 3: Prebuilt binaries

Mafa is a command-line tool that helps people interact with online websites in a terminal(tty).
Mafa is a command-line tool that helps people interact with online websites in a terminal(tty).

A Small Demo Installation Prerequisite Option 1: Cargo install (recommended) Option 2: Build from source Option 3: Prebuilt binaries Mafa is for me? W

This is a command line utility written in Rust that helps you plan factories in Satisfactory.

Satisfactory Factory Planning Utility This is a command line utility written in Rust that helps you plan factories in Satisfactory. Tell it what you w

Jupyter extension for Rust.

rustdef Jupyter extension for jupyter notebook and rust user. You can define functions in rust and run them as python functions. This extension is bui

This automatically patches the RoPro extension for you, allowing you to have pro_tier for free.

RoPro Patcher This automatically patches the RoPro extension for you, allowing you to have pro_tier for free. NOTE Chrome, Brave (and possibly other b

Plain Rust wrapper of Ableton Link's C 11 extension

rusty_link rusty_link is a Rust wrapper of abl_link, which is a C 11 extension for Ableton Link, provided by Ableton. This library attempts to be most

FileSorterX is an automatic file sorting application that sorts your files into folders based on their file extension
FileSorterX is an automatic file sorting application that sorts your files into folders based on their file extension

FileSorterX is an automatic file sorting application that sorts your files into folders based on their file extension. With FileSorterX, you can easily keep your files organized and find what you need quickly.

Owner
ShakaCode
We build web and mobile applications using React, ReScript, React-Native, Ruby on Rails, and Rust
ShakaCode
A Rust CLI tool that helps you enforce Git policies through Git hooks both server and client side

GitPolicyEnforcer This is a command line utility written in Rust, that helps you utilize Git hooks, to enforce various policies. It currently supports

Vagelis Prokopiou 4 Aug 14, 2022
Helps cargo build and run apps for iOS

cargo-xcodebuild Helps cargo build and run apps for iOS. ?? ⚙️ ?? Setup You need to install Xcode (NOT just Command Line Tools!), xcodegen, cargo-xcod

Igor Shaposhnik 29 Nov 22, 2022
Deadliner helps you keep track of the time left for your deadline by dynamically updating the wallpaper of your desktop with the time left.

Deadliner Watch the YouTube video What's Deadliner? Deadliner is a cross-platform desktop application for setting deadline for a project and keeping t

Deadliner 34 Dec 16, 2022
gfold is a CLI-driven application that helps you keep track of multiple Git repositories.

gfold is a CLI-driven application that helps you keep track of multiple Git repositories.

Nick Gerace 215 Jan 4, 2023
Helps you keep track of time for team members across different time zones & DST changes

Teamdate Helps you keep track of time for team members across different timezones and other daylight saving changes based off their location. Because

Alex Snaps 7 Jan 9, 2023
A Yocto setup and management tool that helps you keep your environment up-to-date and in-sync with your team

yb (Yocto Buddy) yb is designed to make it easy to setup and (perhaps more importantly) keep Yocto environments up-to-date and in-sync with your team.

null 13 Oct 31, 2022
Safer Nostr is a service that helps protect users by loading sensitive information (IP leak) and using AI to prevent inappropriate images from being uploaded.

Safer Nostr is a service that helps protect users by loading sensitive information (IP leak) and using AI to prevent inappropriate images from being uploaded. It also offers image optimization and storage options. It has configurable privacy and storage settings, as well as custom cache expiration.

Thomas 4 Dec 29, 2022
🔣 nerdfix helps you to find/fix obsolete Nerd Font icons in your project.

?? nerdfix nerdfix helps you to find/fix obsolete Nerd Font icons in your project. ?? Why Nerd Fonts is used in many projects for a beautiful UI. It p

Loi Chyan 80 Apr 8, 2023
Sleek is a CLI tool for formatting SQL. It helps you maintain a consistent style across your SQL code, enhancing readability and productivity.

Sleek: SQL Formatter ✨ Sleek is a CLI tool for formatting SQL. It helps you maintain a consistent style across your SQL code, enhancing readability an

Nick Rempel 40 Apr 20, 2023
rpm (Rust project manager) is a tool that helps you to manage your rust projects

rpm rpm (Rust project manager) is a open source tool for managing your rust project in an organized way Installation # make sure you have rust install

Dilshad 4 May 4, 2023