Skip to content
This repository has been archived by the owner on Dec 12, 2024. It is now read-only.

Commit

Permalink
fix/chore: paraphrased description of optional fields in structs (#312)
Browse files Browse the repository at this point in the history
  • Loading branch information
novusnota authored Jul 11, 2024
1 parent f88202b commit 88480ba
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions pages/book/structs-and-messages.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -38,21 +38,24 @@ struct Line {
}
```

Structs can also include both default fields and optional fields. This can be quite useful when you have many fields but don't want to keep respecifying them.
Structs can also contain default fields and define fields of [optional types](/book/optionals). This can be useful if you have a lot of fields, but don't want to keep having to specify common values for them in [new instances](#instantiate).

```tact
struct Params {
name: String = "Satoshi"; // default value
age: Int?; // optional field
point: Point; // nested Structs
name: String = "Satoshi"; // default value
age: Int?; // field with an optional type Int?
// and default value of null
point: Point; // nested Structs
}
```

Structs are also useful as return values from getters or other internal functions. They effectively allow a single getter to return multiple return values.

```tact
contract StructsShowcase {
params: Params; // Struct as a Contract persistent state variable
params: Params; // Struct as a contract's persistent state variable
init() {
self.params = Params{
Expand Down

0 comments on commit 88480ba

Please sign in to comment.