Settings

Theme

Show HN: Patina – Python adaptations of Rust's Option, Result, and HashMap

github.com

3 points by p7g 5 years ago · 1 comment

Reader

p7gOP 5 years ago

I've been writing a library that implements some of Rust's types in Python. At this point it's got Option, Result, and HashMap. It tries to match Rust's API exactly where possible, while also supporting the things you would expect in Python like __len__, __iter__, etc.

I ported the Rust documentation as well, using docstrings. The examples in the docstrings are run as tests, and each doctest must be well-typed (according to mypy) for CI to pass.

There are a few reasons why I made this:

- mypy with typing.Optional can enforce checking for None, but it makes me miss Rust APIs like Option.map.

- Python will have pattern matching in 3.10, which will make this library more ergonomically feasible.

- It seemed like a fun and straightforward project.

I'm happy to answer any questions, and would love to hear your constructive criticism.

Keyboard Shortcuts

j
Next item
k
Previous item
o / Enter
Open selected item
?
Show this help
Esc
Close modal / clear selection