Crates.io | typed_macros |
lib.rs | typed_macros |
version | 1.0.6 |
source | src |
created_at | 2022-10-12 00:28:09.756881 |
updated_at | 2022-10-14 17:55:55.688053 |
description | Adds typing to your macro's arguments, making it a lot less of a pain to deal with them. |
homepage | https://github.com/blyxyas/typed_macros |
repository | https://github.com/blyxyas/typed_macros |
max_upload_size | |
id | 685744 |
size | 9,133 |
A traditional macro can't natively have arguments with type, they can only
accept a handful of meta types (expr
, ident
, vis
...), with this crate
you can explicitely say the type of the argument you want the macro to take.
Add the following dependency to your Cargo.toml file:
[dependencies]
typed_macros = "1.0.6"
And check the documentation on how to use it.
#![feature(macro_metavar_expr)]
use typed_macros::macrox;
macrox! {
/// You can even use attributes!
#[macro_export]
macro foo(bar: String) {
// Do something with bar...
}
}
fn main() {
foo!(String::from("Some string")); // <- This won't throw an error.
foo!(9u32); // <- This will throw an error.
}
The main macro is macrox
, it takes an input like macro name(arg1: type1, arg2: type2) { /* Code */ }
Take a look to the documentation for a more in-depth approach to this macro. (Including multibranched macros!)
You can run cargo test
in the root directory, but you'll only see an error (an intended error) because the macro this_should_warn
was asking for a u32
type, and the test tried to use it with a String
.
Contributing is always welcomed, both in the form of code, documentation, ideas, etc... As the project is very simple there isn't a guide for contributing. If this is your first time contributing to an open source project maybe this guide helps you.
Thanks to all the people that starred the project, my monkey brain likes when number grow big.
This software uses the MIT license. More info about this license is in the LICENSE
file.