Skip to content

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

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT
Notifications You must be signed in to change notification settings

WilliamVenner/turbonone

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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!

About

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

Topics

Resources

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT

Stars

Watchers

Forks

Languages