From 4f8135071ae6faf7abfbc2f4765101ce9c0bb287 Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Thu, 19 Dec 2024 16:30:17 +0000 Subject: Define methods directly on struct --- examples/35-extend-struct-inline/shed.toml | 7 ------- examples/35-extend-struct-inline/src/HelloWorld.shed | 20 -------------------- examples/35-struct-methods/shed.toml | 7 +++++++ examples/35-struct-methods/src/HelloWorld.shed | 17 +++++++++++++++++ 4 files changed, 24 insertions(+), 27 deletions(-) delete mode 100644 examples/35-extend-struct-inline/shed.toml delete mode 100644 examples/35-extend-struct-inline/src/HelloWorld.shed create mode 100644 examples/35-struct-methods/shed.toml create mode 100644 examples/35-struct-methods/src/HelloWorld.shed (limited to 'examples') diff --git a/examples/35-extend-struct-inline/shed.toml b/examples/35-extend-struct-inline/shed.toml deleted file mode 100644 index bf5c13c4..00000000 --- a/examples/35-extend-struct-inline/shed.toml +++ /dev/null @@ -1,7 +0,0 @@ -[[shed.bins]] -name = "hello-world" -main-namespace = "HelloWorld" - -[[shed.examples]] -bin = "hello-world" -expected-output = "hello, world" diff --git a/examples/35-extend-struct-inline/src/HelloWorld.shed b/examples/35-extend-struct-inline/src/HelloWorld.shed deleted file mode 100644 index bcdcf023..00000000 --- a/examples/35-extend-struct-inline/src/HelloWorld.shed +++ /dev/null @@ -1,20 +0,0 @@ -pub fun main() ! Io -> Unit { - print!(Count(1).message()); - print!(Count(2).message()); - print!(Count(3).message()); -} - -struct Count(.value: Int) { -} - -extend Count { - fun message(this) -> String { - if (this.value == 1) { - "one\n" - } else if (this.value == 2) { - "two\n" - } else { - "many\n" - } - } -} diff --git a/examples/35-struct-methods/shed.toml b/examples/35-struct-methods/shed.toml new file mode 100644 index 00000000..bf5c13c4 --- /dev/null +++ b/examples/35-struct-methods/shed.toml @@ -0,0 +1,7 @@ +[[shed.bins]] +name = "hello-world" +main-namespace = "HelloWorld" + +[[shed.examples]] +bin = "hello-world" +expected-output = "hello, world" diff --git a/examples/35-struct-methods/src/HelloWorld.shed b/examples/35-struct-methods/src/HelloWorld.shed new file mode 100644 index 00000000..2e0ad2bc --- /dev/null +++ b/examples/35-struct-methods/src/HelloWorld.shed @@ -0,0 +1,17 @@ +pub fun main() ! Io -> Unit { + print!(Count(1).message()); + print!(Count(2).message()); + print!(Count(3).message()); +} + +struct Count(.value: Int) { + fun message(this) -> String { + if (this.value == 1) { + "one\n" + } else if (this.value == 2) { + "two\n" + } else { + "many\n" + } + } +} -- cgit v1.2.3