Skip to content

Attribute macros that prepend or append arbitrary syntax. Useful with `cfg_attr`.

License

Notifications You must be signed in to change notification settings

taylordotfish/add-syntax

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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) { /* ... */ }
}

Documentation

Documentation is available on docs.rs.

License

add-syntax is licensed under version 2 of the Apache License. See LICENSE.

Contributing

By contributing to add-syntax, you agree that your contribution may be used according to the terms of add-syntax’s license.

About

Attribute macros that prepend or append arbitrary syntax. Useful with `cfg_attr`.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages