Macro to customize the behavior of `?`

Overview

::custom-try

Macro to customize the behavior of ?

Repository Latest version Documentation MSRV unsafe forbidden License CI

Examples

use ::custom_try::custom_try;

#[repr(transparent)]
pub struct FfiResult {
    pub status_code: ::std::os::raw::c_int,
}

impl FfiResult {
    pub const OK: Self = Self { status_code: 0 };
    pub const ERR: Self = Self { status_code: -1 };
}

macro_rules! unwrap_option {( $option:expr $(,)? ) => (
    match $option {
        Some(thing) => thing,
        None => return FfiResult::ERR,
    }
)}

#[custom_try(unwrap_option!)]
extern "C" fn ffi_function() -> FfiResult {
    let x = the_answer_to_life_the_universe_and_everything()?;
    println!("{}", x);
    FfiResult::OK
}

/// If you only have one case of `?` semantics, you can default to that one
/// using the default `r#try!` macro name.
use unwrap_option as r#try;

#[custom_try]
extern "C" fn ffi_function2() -> FfiResult {
    let x = the_answer_to_life_the_universe_and_everything()?;
    println!("{}", x);
    FfiResult::OK
}
You might also like...
A HTML to node macro powered by rstml.

html-node A HTML to node macro powered by rstml. Features Text escaping Pretty-printing NEW: type-safe elements and attributes! (example) Example let

Macro to print variable(s) with values nicely (stripped from release builds)

log_macro Macro to print variable(s) with values nicely (stripped from release builds) Install cargo add log_macro Use Add this to top of file: #[mac

Enhance Rust errors with file and line details using the `#[wherr]` macro for clearer debugging.

wherr Crate Discuss wherr on Hacker News Enhance Rust's ? operator by appending file and line number details to errors, simplifying the debugging proc

This library provides a convenient derive macro for the standard library's std::error::Error trait.

derive(Error) This library provides a convenient derive macro for the standard library's std::error::Error trait. [dependencies] therror = "1.0" Compi

A Rust macro for quickly unwrapping a refutable pattern.

unwrap_let! A Rust macro for quickly unwrapping a refutable pattern. Install Add unwrap_let to your dependency by running cargo add unwrap_let or edit

Just provide a macro for a certain programming language.

Trust me, this is safe! A macro wrap unsafe keyword into safe! macro. Always trust programmers. use std::alloc::{alloc, dealloc, Layout}; use trust_m

A procedural macro that copy-pastes match arms for new type variant enums.

All the same! If you ever had code that looks like this: use std::io; use std::pin::Pin; use std::task::{Context, Poll}; use tokio::io::AsyncWrite; us

Style terminal outputs in a minimal, macro-based, and dead simple way.

sty 🌈 $\mathbb{\color{red}{Style \ } \color{lightblue}{terminal}\ \color{black}{outputs \ }\color{gray}{\ in\ a} \color{magenta}{\ minimal}\color{gra

The sysroot manager that lets you build and customize `std`
The sysroot manager that lets you build and customize `std`

PSA: Xargo is in maintenance mode xargo The sysroot manager that lets you build and customize std Cross compiling `std` for i686-unknown-linux-gnu Xar

wasmy, easily customize my wasm app

wasmy wasmy, easily customize my wasm app! features Completely shield vm-wasm interaction details Simple and flexible ABI, supports freely adding vm a

The Heros NFT Marketplace Boilerplate project is designed to let users fork, customize, and deploy their own nft marketplace app to a custom domain, ultra fast.

Heros NFT on Solana The Heros NFT Marketplace Boilerplate project is designed to let users fork, customize, and deploy their own nft marketplace app t

VSCode extension to quickly write and customize well tested Solana snippets.
VSCode extension to quickly write and customize well tested Solana snippets.

Solana Snippets The Solana Snippets VSCode Extension allows you to quickly insert Solana snippets into your code. This snippets are well tested in a r

Customize window border colors :3
Customize window border colors :3

cute-borders Makes focused and unfocused window borders have a different border color, configurable per program. Windows 11 only. Preview Installing D

QueingSimulator is an application that can be used to build intuitions about behavior of synchronous request/reply systems

Queueing Simulator QueingSimulator is an application that can be used to build intuitions about behavior of synchronous request/reply systems (such as

A set of utilities to better enable polymorphic behavior in Rust

Polymorph A set of utilities to better enable polymorphic behavior in Rust. Introduction Rust is a wonderful language, with a strong emphasis on fast,

Rust Memory Safety & Undefined Behavior Detection

Rudra is a static analyzer to detect common undefined behaviors in Rust programs. It is capable of analyzing single Rust packages as well as all the packages on crates.io.

A Rust compiler plugin and support library to annotate overflow behavior

overflower This project contains a compiler plugin and supporting library to allow the programmer to annotate their code to declare how integer overfl

Fox Ear is a Linux process behavior trace tool powered by eBPF
Fox Ear is a Linux process behavior trace tool powered by eBPF

Fox Ear Fox Ear is a Linux process behavior trace tool powered by eBPF. Banner image by Birger Strahl on Unsplash. Features Log process and its subpro

Rust implementation of behavior trees.
Rust implementation of behavior trees.

Bonsai 盆栽 Rust implementation of Behavior Trees Contents Quick intro to Behavior Trees Concepts Examples Development Guide Kanban Board Honorable Ment

Owner
Daniel Henry-Mantilla
Thinking about the immortality of the 🦀 https://danielhenrymantilla.github.io
Daniel Henry-Mantilla
A crate to help you copy things into raw buffers without invoking spooky action at a distance (undefined behavior).

?? presser Utilities to help make copying data around into raw, possibly-uninitialized buffers easier and safer. presser can help you when copying dat

Embark 131 Mar 16, 2023
Quick'n dirty macro set for advent of code 2021

AOC quick'n dirty macro set Those are implemented using quick'n dirty procedural macros and libraries. Running the program Use cargo run --release --

Samuel Tardieu 3 Dec 25, 2021
Semantic find-and-replace using tree-sitter-based macro expansion

Semantic find-and-replace using tree-sitter-based macro expansion

Isaac Clayton 15 Nov 10, 2022
An html macro for dioxus applications.

dioxus html macro This crate offers an html! like macro for dioxus applications. It expands to the equivalent rsx! macro call you would have made othe

Dioxus Labs 8 Dec 22, 2022
An attribute macro to simplify writing simple command line applications.

fncli An attribute macro to simplify writing simple command line applications. Example #[fncli::cli] fn main(a: i32, b: i32) { println!("{}", a +

Vidhan Bhatt 29 Dec 15, 2022
A micro crate that simplifies a bit the use of the std macro thread_local!.

with-thread-local A micro crate that simplifies a bit the use of the std macro thread_local!. extern crate regex; use with_thread_local::with_thread_

Cecile Tonglet 3 Jan 11, 2023
A convenient macro for building PathBufs in Rust.

pathbuf pathbuf is a simple crate which provides the pathbuf macro to conveniently construct the Rust PathBuf type. Example use pathbuf::pathbuf; use

Andrew Lilley Brinker 6 Jan 16, 2023
A formatter for the leptos view! macro

leptosfmt A formatter for the leptos view! macro All notable changes are documented in: CHANGELOG.md Install cargo install leptosfmt or for trying out

Bram 13 Apr 4, 2023
Flexible deriving macro.

This library is a slightly more convenient version of derive for newtype pattern. => See also Deriving via Basic Usage #[derive(DerivingVia)] and then

Mitama 24 Mar 26, 2023
ChatGPT powered Rust proc macro that generates code at compile-time.

gpt-macro ChatGPT powered Rust proc macro that generates code at compile-time. Implemented Macros auto_impl!{} #[auto_test(...)] Usage Get ChatGPT API

Akira Moroo 429 Apr 15, 2023