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
- Host: GitHub
- URL: https://github.com/williamvenner/turbonone
- Owner: WilliamVenner
- License: apache-2.0
- Created: 2021-03-31T22:18:19.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2021-04-03T21:02:50.000Z (about 5 years ago)
- Last Synced: 2025-10-03T15:09:15.634Z (8 months ago)
- Topics: generic, generics, macro, no-std, nostd, option, proc-macro, turbofish
- Language: Rust
- Homepage: https://crates.io/crates/turbonone
- Size: 12.7 KB
- Stars: 4
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE-APACHE
Awesome Lists containing this project
README
[](https://crates.io/crates/turbonone)
[](https://docs.rs/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!
```