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...
Discord bot for the Tegaki Tuesday handwriting challenge ๐Ÿšง WIP NOT PRODUCTION ๐Ÿšง
Discord bot for the Tegaki Tuesday handwriting challenge ๐Ÿšง WIP NOT PRODUCTION ๐Ÿšง

ๅญ—(ใ˜)ใกใ‚ƒใ‚“ ๅญ—(ใ˜)ใกใ‚ƒใ‚“ is the Discord bot for the Tegaki Tuesday handwriting challenge. For more information on the challenge, please visit the website. She

Estimate the amount of time spent working on a Git repository

jikyuu (ๆ™‚็ตฆ) A tool to estimate the amount of time spent working on a Git repository. It is a direct port of git-hours, written in Node.js, because the

Quickly find all blackhole directories with a huge amount of filesystem entries in a flat structure
Quickly find all blackhole directories with a huge amount of filesystem entries in a flat structure

findlargedir About Findlargedir is a tool specifically written to help quickly identify "black hole" directories on an any filesystem having more than

idf-env tool helps set up and manage ESP-IDF installations

idf-env Tool for maintaining ESP-IDF environment. Quick start Install serial drivers for ESP boards on Windows. Execute following command in PowerShel

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

Custom memory allocator that helps discover reads from uninitialized memory

libdiffuzz: security-oriented alternative to Memory Sanitizer This is a drop-in replacement for OS memory allocator that can be used to detect uses of

egui-tetra is a library that helps integrate egui

egui-tetra is a library that helps integrate egui, an immediate mode GUI library, with Tetra, a 2D game framework.

Helps positioning your tauri windows.

Tauri plugin positioner A plugin for tauri that helps positioning you windows at well known locations. Install Rust [dependencies] tauri-plugin-positi

Custom memory allocator that helps discover reads from uninitialized memory

libdiffuzz: security-oriented alternative to Memory Sanitizer This is a drop-in replacement for OS memory allocator that can be used to detect uses of

A tool that generates a Sublime Text project file that helps you get started using Scoggle.

README A tool that generates a Sublime Text project file that helps you get started using Scoggle. While Scoggle-Gen may not find every single source

"putzen" is German and means cleaning. It helps keeping your disk clean of build and dependency artifacts safely.

Putzen "putzen" is German and means cleaning. It helps keeping your disk clean of build and dependency artifacts safely. About In short, putzen solves

Tagref helps you maintain cross-references in your code.

Tagref helps you maintain cross-references in your code. You can use it to help keep things in sync, document assumptions, manage invariants, etc. Airbnb uses it for their front-end monorepo. You should use it too!

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

Rust library that helps you change the domain of the link to another domain ๐Ÿฆ€๐Ÿ”

Rust library that helps you to change the domain of the link to another domain, the library helps with privacy. It can be used to change the domain of sites that do not care about privacy to another that does.

Libium is the backend of Ferium. It helps manage Minecraft mods from Modrinth, CurseForge, and Github Releases

Libium Libium is the backend of Ferium. It helps manage Minecraft mods from Modrinth, CurseForge, and Github Releases There are 3 main components in L

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 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

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.

ReadySet is a lightweight SQL caching engine written in Rust that helps developers enhance the performance and scalability of existing applications.
ReadySet is a lightweight SQL caching engine written in Rust that helps developers enhance the performance and scalability of existing applications.

ReadySet is a SQL caching engine designed to help developers enhance the performance and scalability of their existing database-backed applications. W

Beaker helps simplify CosmWasm development workflow.
Beaker helps simplify CosmWasm development workflow.

Beaker Beaker makes it easy to scaffold a new cosmwasm app, with all of the dependencies for osmosis hooked up, interactive console, and a sample fron

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 32 Nov 15, 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 200 Nov 26, 2022
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 5 Sep 16, 2022
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
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

Ryosuke Kamesawa 19 Nov 6, 2022
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

Stefan 6 Oct 28, 2022
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

anzbert 5 Oct 30, 2022
A unix-friendly map-reduce parallelization alternative

slb: sharded load balancer Like parallel --pipe --roundrobin but load balancing is performed based on input line hashing. When performing keyed aggreg

Vladimir Feinberg 29 Dec 8, 2021