Crates.io | turbonone |
lib.rs | turbonone |
version | 0.2.1 |
source | src |
created_at | 2021-03-31 22:21:03.698821 |
updated_at | 2021-04-03 21:02:56.871851 |
description | Simple macro for calling functions with Option |
homepage | |
repository | https://github.com/WilliamVenner/turbonone |
max_upload_size | |
id | 376358 |
size | 18,632 |
Tiny macro for calling functions with generic Option<T>
arguments.
Add to your Cargo.toml file:
[dependencies]
turbonone = "0.*"
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!
#[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!