Skip to content

Commit

Permalink
add static methods
Browse files Browse the repository at this point in the history
  • Loading branch information
mertcandav committed Jul 20, 2023
1 parent 7368c5b commit dc47777
Showing 1 changed file with 30 additions and 1 deletion.
31 changes: 30 additions & 1 deletion src/common-concepts/structures.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).
:::
:::


## 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()
}
```

0 comments on commit dc47777

Please sign in to comment.