3 unstable releases
Uses old Rust 2015
0.2.1 | Apr 3, 2021 |
---|---|
0.2.0 | Apr 1, 2021 |
0.1.3 | Mar 31, 2021 |
#2770 in Rust patterns
24 downloads per month
7KB
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!