30 lines
644 B
Mojo
30 lines
644 B
Mojo
# probe: passing to a var argument: with ^, and with .copy()
|
|
struct Loud(Copyable, Movable):
|
|
var name: String
|
|
|
|
def __init__(out self, name: String):
|
|
self.name = name
|
|
print("init", name)
|
|
|
|
def __init__(out self, *, copy: Self):
|
|
self.name = copy.name + "'"
|
|
print("copy", copy.name)
|
|
|
|
def __init__(out self, *, deinit move: Self):
|
|
self.name = move.name^
|
|
print("move", self.name)
|
|
|
|
def __deinit__(deinit self):
|
|
print("destroy", self.name)
|
|
|
|
|
|
def take(var t: Loud):
|
|
print("took", t.name)
|
|
|
|
|
|
def main():
|
|
var a = Loud("a")
|
|
take(a.copy())
|
|
take(a^)
|
|
print("end")
|