Skip to content

Optional

IsaacShelton edited this page Nov 13, 2022 · 7 revisions

Optional

Optional represents the type of a value that might exist.

Specifications

Type Size Memory Management Model File
Optional ? bytes Scoped 2.8/Optional.adept

Definition

struct <$T> Optional (value $T, has bool)

where

$T is any valid type

Fields

Name Type Description
has bool Whether a value exists
value $T Wrapped value, only exists if has is true

Value Management Definitions

  • verbatim func __defer__(this *<$T> Optional)

Memory Management

optional.value is freed at the end of the scope if optional.has is true.

Functions

  • func none() <$T> Optional

    Returns an empty optional. Should be used with ~> operator like none() ~> <int> Optional.

    [view src]

  • func some(contained POD $T) <$T> Optional

    Returns an optional with a contained value. The contained value is copied byte for byte, so some values may need modifications before being given to this function.

    [view src]

Methods

  • func set(this *<$T> Optional, value POD $T) void

    Sets an optional to a value. The value is copied byte for byte, so some values may need modifications before being given to this function.

    [view src]

  • func get(this *<$T> Optional) $T

    Gets the contained value of an optional.

    [view src]

  • func getPointer(this *<$T> Optional) *$T

    Gets a pointer to the contained value of an optional.

    [view src]

  • func rid(this *<$T> Optional) void

    Sets an optional to not contain anything.

    [view src]

Settings

#default optional_warn_no_value true
Clone this wiki locally