From db690b368f7e05b242f2e775f620f35ab0df5bc3 Mon Sep 17 00:00:00 2001 From: Zuhaitz Méndez Fernández de Aránguiz Date: Tue, 20 Jan 2026 11:16:11 +0000 Subject: Smart derives... --- README.md | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'README.md') diff --git a/README.md b/README.md index c0275c7..cdba0f3 100644 --- a/README.md +++ b/README.md @@ -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 -- cgit v1.2.3