turbonone

Crates.ioturbonone
lib.rsturbonone
version0.2.1
sourcesrc
created_at2021-03-31 22:21:03.698821
updated_at2021-04-03 21:02:56.871851
descriptionSimple macro for calling functions with Option arguments
homepage
repositoryhttps://github.com/WilliamVenner/turbonone
max_upload_size
id376358
size18,632
William (WilliamVenner)

documentation

README

crates.io docs.rs license

turbonone (no_std)

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

Usage

Add to your Cargo.toml file:

[dependencies]
turbonone = "0.*"

The Problem

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

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

fn my_complex_function<T>(arg: Option<Arc<Box<T>>>) -> &'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

#[macro_use] extern crate turbonone;

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

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

fn my_complex_function<T>(arg: Option<Arc<Box<T>>>) -> &'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<Box<()>>)); // Works!
my_complex_function(Some(Arc::new(Box::new("An argument")))); // Works!
Commit count: 8

cargo fmt