Crates.io | xmacro |
lib.rs | xmacro |
version | |
source | src |
created_at | 2024-02-26 13:39:55.917026 |
updated_at | 2025-01-12 19:07:53.744424 |
description | rust macro producing multiple expansions |
homepage | |
repository | https://git.pipapo.org/cehteh/xmacro.git |
max_upload_size | |
id | 1153694 |
Cargo.toml error: | TOML parse error at line 24, column 1 | 24 | autolib = false | ^^^^^^^ unknown field `autolib`, expected one of `name`, `version`, `edition`, `authors`, `description`, `readme`, `license`, `repository`, `homepage`, `documentation`, `build`, `resolver`, `links`, `default-run`, `default_dash_run`, `rust-version`, `rust_dash_version`, `rust_version`, `license-file`, `license_dash_file`, `license_file`, `licenseFile`, `license_capital_file`, `forced-target`, `forced_dash_target`, `autobins`, `autotests`, `autoexamples`, `autobenches`, `publish`, `metadata`, `keywords`, `categories`, `exclude`, `include` |
size | 0 |
XMacro
A powerful macro system for generating repetitive code using a simple and expressive syntax.
This crate provides two main components:
xmacro!
] and [xmacro_items!
] for direct use in your codeThis crate supersedes the code_product
crate.
For example given are the two sets of defintions 'Foo and Bar' and 'This and That', showing different syntactic variants:
Normal definitions expans each-by-each:
# use xmacro::xmacro;
trait Trait<T>{}
struct This; struct That;
struct Foo<T>(T); struct Bar<T>(T);
xmacro!{
// Rather elaborate form with named definitions:
$(T: (This) (That))
$(Type: (Foo) (Bar))
// and inline define `T` to expand to `Foo` and `Bar`
impl Trait<$T> for $Type<$T> {}
}
or
# use xmacro::xmacro;
# trait Trait<T>{}
# struct This; struct That;
# struct Foo<T>(T); struct Bar<T>(T);
xmacro!{
// Alternative form inlining/short definition and reference by index:
impl Trait<$(This That)> for $(Foo Bar)<$0> {}
}
or use the table syntax expands per table row and gives more control what gets expansed:
# use xmacro::xmacro;
# trait Trait<T>{}
# struct This; struct That;
# struct Foo<T>(T); struct Bar<T>(T);
xmacro!{
// Tables have a header line followed by a vertical list of expansions
// they would be more interesting when defining more than one thing in the header
$[
T: Type:
(This) (Foo)
(That) (Foo)
(This) (Bar)
(That) (Bar)
]
// and inline define `T` to expand to `Foo` and `Bar`
impl Trait<$T> for $Type<$T> {}
}
either of the above will expand four times to:
# trait Trait<T>{}
# struct This; struct That;
# struct Foo<T>(T); struct Bar<T>(T);
impl Trait<This> for Foo<This> {}
impl Trait<That> for Foo<That> {}
impl Trait<This> for Bar<This> {}
impl Trait<That> for Bar<That> {}
Please refer to the xmacro_lib crate for a elaborate description of the macro syntax and semantic.