Skip to content

Built-In Derives

@derive(Debug, Eq, Clone) instructs the compiler to generate implementations of the named traits for the annotated type. The built-in derives are themselves written in Zolo via the same @derive_for mechanism — no privileged compiler path — so they serve as executable documentation for writing custom derives.

Apply @derive(Debug, Eq, Clone) to a User struct, then verify tostring, equality comparison, and clone all work without any hand-written impl.

11-derive-builtin.zolo
Playground
// Feature: `@derive(Trait)` generates trait impls at compile time. The built-in

// derives (Debug, Eq, Clone for structs; Eq/Clone/Hash/Ord for newtypes) are

// themselves written in Zolo via the same public `@derive_for` mechanism

// (dogfooded — no privileged compiler path).


@derive(Debug, Eq, Clone)
struct User { id: int, name: str }

let u = User.new(7, "ada")
print(tostring(u))
// expected: User { id: 7, name: ada }

print(u == User.new(7, "ada"))
// expected: true

let c = u.clone()
print(c == u)
// expected: true

enespt-br