Skip to content

Commit

Permalink
Add Option type (#1232)
Browse files Browse the repository at this point in the history
* Reopening fix for #485

* Reopening fix for #485

* Fixed formatting #485

The tip formatting was not correct, it needed a blank line above and under the tip markdown.

* Fixing formatting issue #485

* Update docs/learn/encyclopedia/contract-development/types/built-in-types.mdx

Co-authored-by: Elliot Voris <[email protected]>

* fix markdown formatting?

---------

Co-authored-by: Elliot Voris <[email protected]>
Co-authored-by: Elliot Voris <[email protected]>
  • Loading branch information
3 people authored Feb 7, 2025
1 parent bda86cd commit 5323b1c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Built-in types are available to all contracts for use as contract function input

:::tip

Custom types like structs, enums, and unions are also supported. See [Custom Types]. [Custom Types]: custom-types.mdx
Custom types like structs, enums, and unions are also supported. See Custom Types.

:::

Expand Down Expand Up @@ -87,3 +87,11 @@ Address is a universal opaque identifier to use in contracts. It may represent a
Address can be used as a contract function input argument (for example, to identify the payment recipient), as a data key (for example, to store the balance), as the authentication & authorization source (for example, to authorize a token transfer) etc.

See [authorization documentation](../../security/authorization.mdx) for more details on how to use the `Address` type.

## Option (`Option`)

Option represents an optional value.

The Option type is used for values that may, or may not, be present. The Option type is an enum and can either be `Some` (some value exists) or `None` (no value exits).

While Option acts like Rust's `Option<T>`, the Option type is not explicitly represented in XDR. The Option type is represented in the XDR by the `ScVal` `ScVoid` value when no value exists (None), any by any other `ScVal` value when the value exists (Some).
2 changes: 2 additions & 0 deletions docs/tools/sdks/build-your-own.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ Below is a list of functionality a Soroban SDK needs to support those things, as
- [Val] encode/decode
- [Object] encode/decode
- [Symbol] encode/decode
- [Option] encode/decode
- [Error] encode/decode

### Host Functions
Expand Down Expand Up @@ -90,6 +91,7 @@ The test environment should include:
[error]: https://github.com/stellar/rs-soroban-env/blob/main/soroban-env-common/src/error.rs
[object]: https://github.com/stellar/rs-soroban-env/blob/main/soroban-env-common/src/object.rs
[symbol]: https://github.com/stellar/rs-soroban-env/blob/main/soroban-env-common/src/symbol.rs
[option]: https://github.com/stellar/rs-soroban-env/blob/main/soroban-env-common/src/option.rs
[env.json]: https://github.com/stellar/rs-soroban-env/blob/main/soroban-env-common/env.json
[map]: https://github.com/stellar/rs-soroban-sdk/blob/main/soroban-sdk/src/map.rs
[vec]: https://github.com/stellar/rs-soroban-sdk/blob/main/soroban-sdk/src/vec.rs
Expand Down

0 comments on commit 5323b1c

Please sign in to comment.