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

Rustato: A powerful, thread-safe global state management library for Rust applications, offering type-safe, reactive state handling with an easy-to-use macro-based API.
Rustato: A powerful, thread-safe global state management library for Rust applications, offering type-safe, reactive state handling with an easy-to-use macro-based API.

Rustato State Manager A generical thread-safe global state manager for Rust Introduction • Features • Installation • Usage • Advanced Usage • Api Refe

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