Skip to content

Instantly share code, notes, and snippets.

@modularbot
Created May 2, 2024 12:58
Show Gist options
  • Save modularbot/2be7ca18bd18cb20ec08538b38515aaf to your computer and use it in GitHub Desktop.
Save modularbot/2be7ca18bd18cb20ec08538b38515aaf to your computer and use it in GitHub Desktop.
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