"""Error handling with the `Result` type."""fromtypingimportGeneric,no_type_checkfromguppylang_internals.decoratorimportcustom_function,custom_typefromguppylang_internals.definition.customimportNoopCompilerfromguppylang_internals.std._internal.compiler.eitherimport(EitherConstructor,EitherTestCompiler,EitherUnwrapCompiler,either_to_hugr,)fromguppylang_internals.tys.paramimportTypeParamfromguppylangimportguppyfromguppylang.std.builtinsimportownedfromguppylang.std.eitherimportEitherT=guppy.type_var("T",copyable=False,droppable=False)E=guppy.type_var("E",copyable=False,droppable=False)_params=[TypeParam(0,"T",False,False),TypeParam(1,"E",False,False)]
[docs]@custom_type(either_to_hugr,params=_params)classResult(Generic[T,E]):# type: ignore[misc]"""Represents a union of either an `ok(T)` or an `err(E)` value."""
[docs]@custom_function(EitherTestCompiler(0))@no_type_checkdefis_ok(self:"Result[T, E]")->bool:"""Returns `True` for an `ok` value."""
[docs]@custom_function(EitherTestCompiler(1))@no_type_checkdefis_err(self:"Result[T, E]")->bool:"""Returns `True` for an `err` value."""
[docs]@custom_function(EitherUnwrapCompiler(0))@no_type_checkdefunwrap(self:"Result[T, E]"@owned)->T:"""Returns the contained `ok` value, consuming `self`. Panics if `self` is an `err` value. """
[docs]@custom_function(EitherUnwrapCompiler(1))@no_type_checkdefunwrap_err(self:"Result[T, E]"@owned)->E:"""Returns the contained `err` value, consuming `self`. Panics if `self` is an `ok` value. """
[docs]@custom_function(NoopCompiler())@no_type_checkdefinto_either(self:"Result[T, E]"@owned)->Either[T,E]:"""Casts a `Result` value into an `Either` value."""
[docs]@custom_function(EitherConstructor(0))@no_type_checkdefok(val:T@owned)->Result[T,E]:"""Constructs an `ok` result value."""
[docs]@custom_function(EitherConstructor(1))@no_type_checkdeferr(err:E@owned)->Result[T,E]:"""Constructs an `err` result value."""