duplicate
Crate for easy code duplication with substitution.
Motivation
If you find yourself in need of copying a block of code and then making some small changes to fit the new use case, this crate is for you.
The duplicate
attribute macro will duplicate an item any number of times while inserting custom code in the designated places in each duplicate.
The duplicate_inline
function-like procedural macro will do the same for any code you give it.
For an in-depth explanation of the syntax and features, see the documentation.
Example
use duplicate;
/// Trait we want to implement for u8, u16, and u32
assert!;
assert!;
assert!;
Expands to:
use duplicate;
/// Trait we want to implement for u8, u16, and u32
assert!;
assert!;
assert!;
MSRV Policy
This crate's Minimum Supported Rust Version (MSRV) depends on which features are enabled.
The Base MSRV is 1.34. It applies when no features are enabled and is the lowest possible MSRV. Enabling the following features increases the MSRV to the stated version:
module_disambiguation
: 1.42
Enabling features not on the above list doesn't increase the MSRV.
Increasing the Base MSRV or the MSRV of any specific existing feature is a breaking change and will be accompanied by a major version bump. Adding new features doesn't count as a breaking change, even if they are enabled by default and thereby increase the commulative MSRV of the default features.
Changelog
This project adheres to Semantic Versioning. During initial development (with versions 0.y.z), bumps to the minor version (y) signify breaking changes.
Added
- Global Substitution: Allows substitutions that are applied to all duplicates equally. See #23.
Changed
- [BREAKING] Limited which group delimiters are allowed in various syntactic positions. The specific delimiters required now follow the use of delimiters in previous documentation examples. See #25.
- Substituted the
convert_case
dependency forheck
. See #22.
Fixed
- Now also substitutes code inside substitution arguments. See #24.
- Module_disambiguation: Now only substitutes the module name and not any matching identifier in the body of the module. See #27.
This changelog format is based on Keep a Changelog and shows only the changes since the previous version. See the full changelog for changes to all released versions.