derive-defs 0.0.6

Library for generating derive preset macros from TOML configuration
Documentation
# derive-defs

[![crates.io](https://img.shields.io/crates/v/derive-defs.svg)](https://crates.io/crates/derive-defs)
[![docs.rs](https://docs.rs/derive-defs/badge.svg)](https://docs.rs/derive-defs)
[![unsafe forbidden](https://img.shields.io/badge/unsafe-forbidden-success.svg)](https://doc.rust-lang.org/nomicon/meet-safe-and-unsafe.html)
[![license](https://img.shields.io/badge/license-MIT%2FApache--2.0-blue)](LICENSE-MIT)

Declarative derive preset configuration via TOML with proc-macro generation.

## Overview

`derive-defs` allows you to define named sets of derive attributes through a
declarative TOML configuration. This is useful when you have common derive
patterns that you use repeatedly across your codebase.

### Why not `macro_rules_attribute`?

Existing solutions require defining aliases directly in code. `derive-defs` offers:

- **External Configuration**: Define presets in TOML, not code
- **Inheritance**: Bundles can extend other bundles via `extends`
- **Cross-file Imports**: Split configuration across multiple files
- **Runtime Modification**: Use `omit`/`add` to modify bundles at use site

## Quick Start

### 1. Create `derive_defs.toml`

```toml
[defs.serialization]
traits = ["Clone", "Serialize", "Deserialize"]
attrs = ['#[serde(rename_all = "camelCase")]']

[defs.model]
traits = ["Debug", "Clone", "PartialEq"]

[defs.entity]
extends = "model"
traits = ["Serialize", "Deserialize"]
attrs = ['#[serde(rename_all = "camelCase")]']
```

### 2. Set up `build.rs`

```rust
fn main() {
    derive_defs::generate("derive_defs.toml")
        .expect("Failed to generate derive defs");
}
```

Add to `Cargo.toml`:

```toml
[build-dependencies]
derive-defs = "0.1"
```

### 3. Use in your code

```rust
use my_crate_macros::*;

#[serialization]
struct User {
    name: String,
    age: u32,
}

// Modify at use site
#[serialization(omit(Clone), add(Default))]
struct Config {
    host: String,
}
```

## TOML Configuration

### Basic Syntax

```toml
[defs.<name>]
traits = ["Trait1", "Trait2"]  # List of derive traits
attrs = ["#[attr]"]             # Additional attributes
extends = "<parent>"            # Inheritance (optional)
```

### Inheritance (`extends`)

```toml
[defs.base]
traits = ["Debug", "Clone"]

[defs.value_object]
extends = "base"
traits = ["PartialEq", "Eq", "Hash"]
# Result: Debug, Clone, PartialEq, Eq, Hash
```

### Cross-file Imports (`includes`)

```toml
[includes]
common = "shared/common_defs.toml"

[defs.api_response]
extends = "common.serialization"
traits = ["Default"]
```

## API Usage

### Attribute Modifiers

```rust
// Basic usage
#[serialization]
struct User { }

// Exclude Clone from the bundle
#[serialization(omit(Clone))]
struct Session { }

// Add Default and Hash to the bundle
#[serialization(add(Default, Hash))]
struct Config { }

// Exclude serde attributes
#[serialization(omit_attrs(serde))]
struct Internal { }

// Combination
#[serialization(omit(Clone), add(Copy))]
struct Flags { }
```

## Error Handling

The crate provides clear error messages at `build.rs` time:

- **Circular inheritance**: `error: circular extends detected: a → b → c → a`
- **Undefined parent**: `error: def "child" extends "parent" which is not defined`
- **Missing include**: `error: include file "common.toml" not found`
- **Duplicate name**: `error: def "model" is defined multiple times`

## License

MIT OR Apache-2.0