dotfiles/vscode/.vscode/extensions/ms-python.black-formatter-2024.2.0/bundled/libs/black/rusty.py
Errol Sancaktar ff17c17e23 vscode
2024-06-14 09:31:58 -06:00

29 lines
557 B
Python

"""An error-handling model influenced by that used by the Rust programming language
See https://doc.rust-lang.org/book/ch09-00-error-handling.html.
"""
from typing import Generic, TypeVar, Union
T = TypeVar("T")
E = TypeVar("E", bound=Exception)
class Ok(Generic[T]):
def __init__(self, value: T) -> None:
self._value = value
def ok(self) -> T:
return self._value
class Err(Generic[E]):
def __init__(self, e: E) -> None:
self._e = e
def err(self) -> E:
return self._e
Result = Union[Ok[T], Err[E]]