add-syntax 0.1.0

Attribute macros that prepend or append arbitrary syntax. Useful with `cfg_attr`.
Documentation
  • Coverage
  • 100%
    3 out of 3 items documented1 out of 3 items with examples
  • Size
  • Source code size: 19.46 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 254.89 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Links
  • taylordotfish/add-syntax
    0 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • taylordotfish

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] is used:

#[cfg_attr(feature = "dropck_eyepatch", add_syntax::prepend(unsafe))]
impl<#[cfg_attr(feature = "dropck_eyepatch", may_dangle)] T> Drop
    for Foo<T>
{
    fn drop(&mut self) { /* ... */ }
}

If the hypothetical feature dropck_eyepatch is enabled, the code above is equivalent to:

unsafe impl<#[may_dangle] T> Drop for Foo<T> {
    fn drop(&mut self) { /* ... */ }
}

Otherwise, if the feature is not enabled, the code is equivalent to:

impl<T> Drop for Foo<T> {
    fn drop(&mut self) { /* ... */ }
}