]> 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:

Update CHANGES.md for 21.5b2 release (#2290)
[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
8 T = TypeVar("T")
9 E = TypeVar("E", bound=Exception)
10
11
12 class Ok(Generic[T]):
13     def __init__(self, value: T) -> None:
14         self._value = value
15
16     def ok(self) -> T:
17         return self._value
18
19
20 class Err(Generic[E]):
21     def __init__(self, e: E) -> None:
22         self._e = e
23
24     def err(self) -> E:
25         return self._e
26
27
28 Result = Union[Ok[T], Err[E]]