-
-
Save modularbot/2be7ca18bd18cb20ec08538b38515aaf to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct DemoStruct(CollectionElement, Stringable): | |
var value: String | |
fn __init__(inout self, value: String) -> None: | |
self.value = value | |
print("Called __init__ for", str(self)) | |
fn __moveinit__(inout self, owned existing: Self) -> None: | |
self.value = existing.value ^ | |
print("Called __moveinit__ for", str(self)) | |
fn __copyinit__(inout self, existing: Self) -> None: | |
self.value = existing.value | |
print("Called __copyinit__ for", str(self)) | |
fn __del__(owned self) -> None: | |
print("Called __del__ for", str(self)) | |
fn __str__(self) -> String: | |
return 'DemoStruct(String("' + self.value + '"))' | |
fn bar(owned foo: DemoStruct): | |
print("Called bar with argument:", str(foo)) | |
fn main(): | |
var foo = DemoStruct(String("foo")) | |
bar(foo) | |
print(foo) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment