Skip to content

Commit e9626a4

Browse files
committed
Mojo
1 parent c8bccd6 commit e9626a4

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

mojo/.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# pixi environments
2+
.pixi/*
3+
!.pixi/config.toml
4+
pixi.lock
5+
pixi.toml

mojo/deinit.mojo

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
@fieldwise_init
2+
struct Balloon(Writable):
3+
var color: String
4+
5+
fn write_to(self, mut writer: Some[Writer]):
6+
writer.write(String("a ", self.color, " balloon"))
7+
8+
fn __del__(deinit self):
9+
print("Destroyed", String(self))
10+
11+
12+
def main():
13+
var a = Balloon("red")
14+
var b = Balloon("blue")
15+
print(a)
16+
# a.__del__() runs here for red Balloon
17+
a = Balloon("green")
18+
# a.__del__() runs immediately because green Balloon is never used
19+
print(b)
20+
# b.__del__() runs here

0 commit comments

Comments
 (0)