summaryrefslogtreecommitdiff
path: root/README.md
diff options
context:
space:
mode:
Diffstat (limited to 'README.md')
-rw-r--r--README.md23
1 files changed, 22 insertions, 1 deletions
diff --git a/README.md b/README.md
index 3103c44..86018f7 100644
--- a/README.md
+++ b/README.md
@@ -457,7 +457,7 @@ fn peek(r: Resource*) { ... } // 'r' is borrowed (reference)
If you *do* want two copies of a resource, make it explicit:
```zc
-var b = a.clone(); // Deep copy: New allocation, safe.
+var b = a.clone(); // Calls the 'clone' method from the Clone trait
```
**Opt-in Copy (Value Types)**:
@@ -595,6 +595,27 @@ fn main() {
}
```
+**Clone**
+
+Implement `Clone` to allow explicit duplication of resource-owning types.
+
+```zc
+import "std/mem.zc"
+
+struct MyBox { val: int; }
+
+impl Clone for MyBox {
+ fn clone(self) -> MyBox {
+ return MyBox{val: self.val};
+ }
+}
+
+fn main() {
+ var b1 = MyBox{val: 42};
+ var b2 = b1.clone(); // Explicit copy
+}
+```
+
#### Composition
Use `use` to embed other structs. You can either mix them in (flatten fields) or name them (nest fields).