GithubHelp home page GithubHelp logo

blyxyas / typed_macros Goto Github PK

View Code? Open in Web Editor NEW
11.0 2.0 2.0 34 KB

Add types to your macros arguments in Rust

Home Page: https://crates.io/crates/typed_macros

License: MIT License

Rust 100.00%
crate macros rust rust-lang rust-macro

typed_macros's Introduction

Typed macros

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.

Usage

Add the following dependency to your Cargo.toml file:

[dependencies]
typed_macros = "1.0.6"

And check the documentation on how to use it.

Example

#![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!)

Testing

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

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.

Stargazers

Thanks to all the people that starred the project, my monkey brain likes when number grow big.

Stargazers repo roster for @blyxyas/typed_macros

License

This software uses the MIT license. More info about this license is in the LICENSE file.

typed_macros's People

Contributors

blyxyas avatar willi-kappler avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.