# sync-code
[](https://github.com/mcu-rust/sync-code/actions)
[](https://crates.io/crates/sync-code)
[](https://docs.rs/sync-code)
[](./LICENSE)
[](https://crates.io/crates/sync-code)
**[sync-code](https://crates.io/crates/sync-code)** synchronizes code blocks across different files, providing a clear alternative to macros in certain scenarios.
When duplication is limited but the design is complex (for example, involving generics), macros often reduce readability and make maintenance harder.
By using **[sync-code](https://crates.io/crates/sync-code)** instead, the code remains straightforward and maintainable, while development tools such as *Go-to-definition* and intelligent auto-completion continue to work as expected.
# Usage
Run command:
```shell
cargo add --build sync-code
```
See [crate](https://crates.io/crates/sync-code).
`build.rs`:
```rust
fn main() {
sync_code::Builder::new()
.add("src/target1.rs", "src/source1.rs")
.add("src/target2.rs", "src/source2.rs")
.sync();
}
```
`your_code.rs`:
```rust
// $sync block_name
fn code_you_want_to_sync() {
}
// $sync end
```
See also [tests](/tests/test.rs).
## 馃敄 Keywords
sync-code 路 rust 路 code generation 路 macro replacement 路 generics 路 readability 路 maintainability 路 developer tools