Skip to content

Commit

Permalink
update structures
Browse files Browse the repository at this point in the history
  • Loading branch information
mertcandav committed Aug 28, 2023
1 parent a33f0bd commit 801d670
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
7 changes: 6 additions & 1 deletion .vitepress/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,12 @@ export default defineConfig({
],
},
{ text: 'Enums', link: '/common-concepts/enums' },
{ text: 'Structures', link: '/common-concepts/structures' },
{
text: 'Structures', link: '/common-concepts/structures/',
items: [
{ text: 'Destructors', link: '/common-concepts/structures/destructors' },
],
},
],
},
{
Expand Down
18 changes: 18 additions & 0 deletions src/common-concepts/structures/destructors.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Destructor Methods

Destructor methods are methods that are called automatically when created instances of structures are destroyed. It is usually used when there is a memory space that needs to be freed, or in similar circumstances.

Destructor methods are called automatically even on immutable instances. There is no harm in mutable operation since it is out of scope. But the need for mutability can arise when you want to call the method manually.

## The Dispose Trait

Jule has a built-in `Dispose` trait. To obtain a destructor method, it is necessary to implement the `Dispose` trait. Structures that implement this trait have a `dispose` method. This method is the destructor method and is called automatically when the build instances are destroyed.

For example:
```jule
impl Dispose for MyStruct {
pub fn dispose(mut self) {
// ...
}
}
```
File renamed without changes.

0 comments on commit 801d670

Please sign in to comment.