Result¶
Result type implementation inspired by Rust's Result enum.
result
¶
Result type implementation inspired by Rust's Result enum.
ResultAccessError
¶
Bases: Error
Exception raised when trying to access value or err from an inappropriate Result variant.
Source code in src/forging_blocks/foundation/result.py
message: ErrorMessage
property
¶
Return the stored message as a string.
__str__() -> str
¶
cannot_access_value() -> ResultAccessError
classmethod
¶
Create an error for accessing value from an Err Result.
cannot_access_error() -> ResultAccessError
classmethod
¶
Create an error for accessing error from an Ok Result.
Result
¶
Bases: Generic[ResultType, ErrorType], Protocol
A type that represents either a success (Ok) or an error (Err).
Source code in src/forging_blocks/foundation/result.py
is_ok: bool
property
¶
Guard method to check if that Result is an ok.
is_err: bool
property
¶
Guard method to check if that Result is an err.
value: ResultType | None
property
¶
Method to return the actual value. May raise an error if Result is an Err.
error: ErrorType | None
property
¶
Method to return the actual error. May raise an error if Result is an Ok.
Ok
¶
Bases: Result[ResultType, ErrorType], Generic[ResultType, ErrorType]
Represents a successful result.
Source code in src/forging_blocks/foundation/result.py
is_err: bool
property
¶
Check if the result is an error.
is_ok: bool
property
¶
Check if the result is ok.
value: ResultType
property
¶
Get the successful value.
error: None
property
¶
Attempting to get error from an Ok result raises an error.
__str__() -> str
¶
__repr__() -> str
¶
__eq__(other: object) -> bool
¶
Err
¶
Bases: Result[ResultType, ErrorType], Generic[ResultType, ErrorType]
Represents an error result.
Source code in src/forging_blocks/foundation/result.py
is_err: bool
property
¶
Check if the result is an error.
is_ok: bool
property
¶
Check if the result is ok.
value: None
property
¶
Attempting to get value from an Err result raises an error.
error: ErrorType
property
¶
Get the error value.