From dc47777a96eadaa3a9136fe8e4cde6991a62e48c Mon Sep 17 00:00:00 2001 From: mertcandav Date: Thu, 20 Jul 2023 19:17:52 +0300 Subject: [PATCH] add static methods --- src/common-concepts/structures.md | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/src/common-concepts/structures.md b/src/common-concepts/structures.md index 9b2bbef..d14c84d 100644 --- a/src/common-concepts/structures.md +++ b/src/common-concepts/structures.md @@ -126,4 +126,33 @@ let pos = &Position{x: 10, y: 20} `pos` variable is the reference points to heap-allocated `Position` structure instance. ::: warning If you not have any idea about references, check the [memory management documentations](/memory/memory-management). -::: \ No newline at end of file +::: + + +## Static Methods + +Static methods, like normal methods, are dependent on the structure itself, but there are some differences. + +These differences are: + +- Can called via type declaration without instances +- Don't dependent to instances +- Don't takes receiver parameters +- Can't access via instances + +For example: + +``` +struct Dog {} + +impl Dog { + static fn voice() { + outln("woof woof") + } +} + +fn main() { + // Call static method via type declaration. + Dog.voice() +} +```