An open API service indexing awesome lists of open source software.

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`.

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.