[docs]@extend_type(option_type_def)classOption(Generic[L]):# type: ignore[misc]"""Represents an optional value."""
[docs]@custom_function(OptionTestCompiler(0))@no_type_checkdefis_nothing(self:"Option[L]")->bool:"""Returns `True` if the option is a `nothing` value."""
[docs]@custom_function(OptionTestCompiler(1))@no_type_checkdefis_some(self:"Option[L]")->bool:"""Returns `True` if the option is a `some` value."""
[docs]@custom_function(OptionUnwrapCompiler())@no_type_checkdefunwrap(self:"Option[L]"@owned)->L:"""Returns the contained `some` value, consuming `self`. Panics if the option is a `nothing` value. """
[docs]@custom_function(OptionUnwrapNothingCompiler())@no_type_checkdefunwrap_nothing(self:"Option[L]"@owned)->None:"""Returns `None` if the option is a `nothing` value, consuming `self`. Panics if the option is a `some` value. """
[docs]@guppy@no_type_checkdefswap(self:"Option[L]",other:"Option[L]"@owned)->"Option[L]":"""Swaps the value of `self` with `other` and returns the original value."""mem_swap(self,other)returnother
[docs]@guppy@no_type_checkdeftake(self:"Option[L]")->"Option[L]":"""Swaps the value of `self` with `nothing` and returns the original value."""returnself.swap(nothing())
[docs]@custom_function(OptionConstructor(0))@no_type_checkdefnothing()->Option[L]:"""Constructs a `nothing` optional value."""
[docs]@custom_function(OptionConstructor(1))@no_type_checkdefsome(value:L@owned)->Option[L]:"""Constructs a `some` optional value."""