https://github.com/taylordotfish/add-syntax
Attribute macros that prepend or append arbitrary syntax. Useful with `cfg_attr`.
https://github.com/taylordotfish/add-syntax
attribute conditional macro macros rust syntax tokens
Last synced: 8 months ago
JSON representation
Attribute macros that prepend or append arbitrary syntax. Useful with `cfg_attr`.
- Host: GitHub
- URL: https://github.com/taylordotfish/add-syntax
- Owner: taylordotfish
- License: apache-2.0
- Created: 2022-12-20T02:41:56.000Z (about 3 years ago)
- Default Branch: master
- Last Pushed: 2022-12-26T03:41:24.000Z (about 3 years ago)
- Last Synced: 2025-05-31T05:39:09.877Z (8 months ago)
- Topics: attribute, conditional, macro, macros, rust, syntax, tokens
- Language: Rust
- Homepage:
- Size: 5.86 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
add-syntax
==========
Attribute macros that prepend or append arbitrary syntax. Useful with
[`cfg_attr`].
This crate provides two attribute macros, [`prepend`] and [`append`], that
add the tokens passed to them to the start or end of the item to which the
attribute is applied, respectively. This is particularly useful with
[`cfg_attr`].
Example
-------
Conditionally applying `unsafe` when [`#[may_dangle]`][may_dangle] is used:
[may_dangle]: https://github.com/rust-lang/rust/issues/34761
```rust
#[cfg_attr(feature = "dropck_eyepatch", add_syntax::prepend(unsafe))]
impl<#[cfg_attr(feature = "dropck_eyepatch", may_dangle)] T> Drop
for Foo
{
fn drop(&mut self) { /* ... */ }
}
```
If the hypothetical feature `dropck_eyepatch` is enabled, the code above
is equivalent to:
```rust
unsafe impl<#[may_dangle] T> Drop for Foo {
fn drop(&mut self) { /* ... */ }
}
```
Otherwise, if the feature is not enabled, the code is equivalent to:
```rust
impl Drop for Foo {
fn drop(&mut self) { /* ... */ }
}
```
[`cfg_attr`]:
https://doc.rust-lang.org/reference/conditional-compilation.html#the-cfg_attr-attribute
[`prepend`]: https://docs.rs/add-syntax/0.1/add_syntax/attr.prepend.html
[`append`]: https://docs.rs/add-syntax/0.1/add_syntax/attr.append.html
Documentation
-------------
[Documentation is available on docs.rs.](https://docs.rs/add-syntax)
License
-------
add-syntax is licensed under version 2 of the Apache License.
See [LICENSE](LICENSE).
Contributing
------------
By contributing to add-syntax, you agree that your contribution may be used
according to the terms of add-syntax’s license.