]> git.madduck.net Git - etc/vim.git/blob - src/black/rusty.py

madduck's git repository

Every one of the projects in this repository is available at the canonical URL git://git.madduck.net/madduck/pub/<projectpath> — see each project's metadata for the exact URL.

All patches and comments are welcome. Please squash your changes to logical commits before using git-format-patch and git-send-email to patches@git.madduck.net. If you'd read over the Git project's submission guidelines and adhered to them, I'd be especially grateful.

SSH access, as well as push access can be individually arranged.

If you use my repositories frequently, consider adding the following snippet to ~/.gitconfig and using the third clone URL listed for each project:

[url "git://git.madduck.net/madduck/"]
  insteadOf = madduck:

Bump mypy[c] from 0.971 to 0.991 (#3380)
[etc/vim.git] / src / black / rusty.py
1 """An error-handling model influenced by that used by the Rust programming language
2
3 See https://doc.rust-lang.org/book/ch09-00-error-handling.html.
4 """
5 from typing import Generic, TypeVar, Union
6
7 T = TypeVar("T")
8 E = TypeVar("E", bound=Exception)
9
10
11 class Ok(Generic[T]):
12     def __init__(self, value: T) -> None:
13         self._value = value
14
15     def ok(self) -> T:
16         return self._value
17
18
19 class Err(Generic[E]):
20     def __init__(self, e: E) -> None:
21         self._e = e
22
23     def err(self) -> E:
24         return self._e
25
26
27 Result = Union[Ok[T], Err[E]]