diff options
| author | 魏曹先生 <1992414357@qq.com> | 2026-08-17 04:33:54 +0800 |
|---|---|---|
| committer | 魏曹先生 <1992414357@qq.com> | 2026-08-17 04:33:54 +0800 |
| commit | 7b901b44cab92b15a673a801de6785c309b73ddd (patch) | |
| tree | fce888b65fc8283107bcba4325e7ca1ef443f4e6 /CHANGELOG.md | |
| parent | aa251efb87b561f62266628f06ad341253fbbdc5 (diff) | |
feat(macros): add Wrap derive macro
Add `#[derive(Wrap)]` to treat a struct as its inner type, generating
`From`, `Deref`, and `DerefMut` implementations. Supports single-field
structs or multi-field structs with a `#[wrap]`-marked field.
Diffstat (limited to 'CHANGELOG.md')
| -rw-r--r-- | CHANGELOG.md | 40 |
1 files changed, 39 insertions, 1 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index 75f1576..ea71a92 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -66,7 +66,45 @@ None #### Features: -None +1. **[`macros:wrap`]** Added the `#[derive(Wrap)]` derive macro that treats a struct as its inner (wrapped) type. The macro generates: + + - `From<Inner> for Self` — construct the wrapper from the inner value + - `From<Self> for Inner` — unwrap back to the inner value (i.e. `Into<Inner>`) + - `Deref` / `DerefMut` — delegate all methods to the inner value + + **Inner field selection:** + + - Tuple struct with one field → that field is the inner type + - Named struct with one field → that field is the inner type + - Named struct with multiple fields → mark exactly one field with `#[wrap]`; the remaining fields are initialized with `Default::default()` when constructing via `From<Inner>` + + **Example:** + + ```rust,ignore + use mingling::macros::Wrap; + + #[derive(Wrap)] + struct Name(String); + + #[derive(Wrap)] + struct Greeting { + name: String, + } + + #[derive(Wrap)] + struct Task { + #[wrap] + content: String, + done: bool, + } + + let name = Name::from("Mingling".to_string()); + // `Deref` forwards methods to the inner `String` + assert_eq!(name.len(), 8); + let inner: String = name.into(); + ``` + + The macro is re-exported from `mingling::Wrap` and `mingling::prelude::Wrap` (feature-gated behind `macros`). #### **BREAKING CHANGES** (API CHANGES): |
