diff options
| author | Zuhaitz Méndez Fernández de Aránguiz <zuhaitz@debian> | 2026-01-20 11:16:11 +0000 |
|---|---|---|
| committer | Zuhaitz Méndez Fernández de Aránguiz <zuhaitz@debian> | 2026-01-20 11:16:11 +0000 |
| commit | db690b368f7e05b242f2e775f620f35ab0df5bc3 (patch) | |
| tree | c70d8e82bf81515e48b7bd2701595d6e62ce93e3 /README.md | |
| parent | f027a812707d68ca0690b7544175b9f302dd57ad (diff) | |
Smart derives...
Diffstat (limited to 'README.md')
| -rw-r--r-- | README.md | 10 |
1 files changed, 9 insertions, 1 deletions
@@ -662,7 +662,15 @@ Decorate functions and structs to modify compiler behavior. | `@weak` | Fn | Weak symbol linkage. | | `@section("name")` | Fn | Place code in specific section. | | `@noreturn` | Fn | Function does not return (e.g. exit). | -| `@derived(...)` | Struct | Auto-implement traits (e.g. `Debug`). | +| `@derive(...)` | Struct | Auto-implement traits. Supports `Debug`, `Eq` (Smart Derive), `Copy`, `Clone`. | + +### Smart Derives + +Zen C provides "Smart Derives" that respect Move Semantics: + +- **`@derive(Eq)`**: Generates an equality method that takes arguments by reference (`fn eq(self, other: T*)`). + - When comparing two non-Copy structs (`a == b`), the compiler automatically passes `b` by reference (`&b`) to avoid moving it. + - Recursive equality checks on fields also prefer pointer access to prevent ownership transfer. ### 14. Inline Assembly |
