Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Option type #1232

Merged
merged 8 commits into from
Feb 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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