An open API service indexing awesome lists of open source software.

https://github.com/williamvenner/turbonone

Tiny macro for calling functions with generic Option<T> arguments
https://github.com/williamvenner/turbonone

generic generics macro no-std nostd option proc-macro turbofish

Last synced: 7 months ago
JSON representation

Tiny macro for calling functions with generic Option<T> arguments

Awesome Lists containing this project

README

          

[![crates.io](https://meritbadge.herokuapp.com/turbonone)](https://crates.io/crates/turbonone)
[![docs.rs](https://docs.rs/turbonone/badge.svg)](https://docs.rs/turbonone/)
[![license](https://img.shields.io/crates/l/turbonone)](https://github.com/WilliamVenner/turbonone/blob/master/LICENSE)

# turbonone (no_std)

Tiny macro for calling functions with generic `Option` arguments.

## Usage

Add to your [Cargo.toml](https://doc.rust-lang.org/cargo/reference/manifest.html) file:

```toml
[dependencies]
turbonone = "0.*"
```

## The Problem

```rust
fn my_function(arg: Option) -> &'static str {
"Works!"
}

fn my_box_function(arg: Option>) -> &'static str {
"Works!"
}

fn my_complex_function(arg: Option>>) -> &'static str {
"Works!"
}

my_function(None); // cannot infer type for type parameter `T` declared on the associated function `my_function`
my_function(Some("An argument")); // Works!

my_box_function(None); // cannot infer type for type parameter `T` declared on the associated function `my_box_function`
my_box_function(Some(Box::new("An argument"))); // Works!

my_complex_function(None); // cannot infer type for type parameter `T` declared on the associated function `my_complex_function`
my_complex_function(Some(Arc::new(Box::new("An argument")))); // Works!
```

## The Solution

```rust
#[macro_use] extern crate turbonone;

fn my_function(arg: Option) -> &'static str {
"Works!"
}

fn my_box_function(arg: Option>) -> &'static str {
"Works!"
}

fn my_complex_function(arg: Option>>) -> &'static str {
"Works!"
}

my_function(turbonone!()); // Works!
my_function(Some("An argument")); // Works!

my_box_function(turbonone!(Box)); // Works!
my_box_function(turbonone!(Box<()>)); // Works!
my_box_function(Some(Box::new("An argument"))); // Works!

my_complex_function(turbonone!(Arc>)); // Works!
my_complex_function(Some(Arc::new(Box::new("An argument")))); // Works!
```