Cloneable

public protocol Cloneable

Protocol for types that need custom logic when duplicated.

Cloneable extends Copyable so that cloneable values can flow through generic code that asks only for Copyable. The compiler invokes clone() automatically wherever a Cloneable value would otherwise be implicitly copied (assignment, argument pass, return). The implementation decides how deep the copy goes — RcBox, for example, only bumps the refcount.

Examples

let a = RcBox(value: 1); let b = a; // implicit clone() — refcount bumps to 2 let c = a.clone(); // explicit clone — refcount bumps to 3

Methods

func clone() -> Self

Returns a copy of self. Conformers define the depth and any side effects (e.g. refcount adjustments).

Defined in lang/std/core/copy.ks