Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.11/site-packages/black/rusty.py: 73%

Shortcuts on this page

r m x   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

15 statements  

1"""An error-handling model influenced by that used by the Rust programming language 

2 

3See https://doc.rust-lang.org/book/ch09-00-error-handling.html. 

4""" 

5 

6from typing import Generic, TypeVar, Union 

7 

8T = TypeVar("T") 

9E = TypeVar("E", bound=Exception) 

10 

11 

12class 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 

20class 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 

28Result = Union[Ok[T], Err[E]]