Yet another Rust's Option<T> and Result<T, E> simple implementation in Python.
Project description
optres
Yet another Rust's Option<T> and Result<T, E> simple implementation in Python.
Installation
python3 -m pip install -U optres
Example
from optres import unwrap, Result, Err, is_ok, is_err, unwrap_err
from typing import LiteralString
def return_result(x: int | None) -> Result[int, LiteralString]:
return Err("not int") if x is None else x
def example() -> None:
a: int | None = 1
c: int = unwrap(a)
print(c)
assert is_ok(return_result(a))
a = None
# unwrap(a) # error := panic in Rust.
may_be_err = return_result(a)
assert is_err(may_be_err)
print(unwrap_err(may_be_err))
if __name__ == "__main__":
example()
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
optres-0.1.0.tar.gz
(7.1 kB
view details)
Built Distribution
File details
Details for the file optres-0.1.0.tar.gz
.
File metadata
- Download URL: optres-0.1.0.tar.gz
- Upload date:
- Size: 7.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.3.2 CPython/3.11.2 Linux/5.15.0-58-generic
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4266feb7dec9e35c344a284d6b9b53ab353e2424f93a302b7ef2217de7602005 |
|
MD5 | ca8ec3f28ce7b85e6d3d365125d78718 |
|
BLAKE2b-256 | c9e8225ecf246eedcfd1a149fbbf87d40b2a826a79c649abec52015ab11629ff |
File details
Details for the file optres-0.1.0-py3-none-any.whl
.
File metadata
- Download URL: optres-0.1.0-py3-none-any.whl
- Upload date:
- Size: 7.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.3.2 CPython/3.11.2 Linux/5.15.0-58-generic
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | fc3e125ccc4693ed3f0a9a5e3004f309c8e8b7926fc736189732209ccd61ac6a |
|
MD5 | 74b319ab08bcde68e5c8f55899a064b6 |
|
BLAKE2b-256 | 9ce1da55dc35ea20d0d295ada7512e3cba4656798d23a8182ffa029223a1dd3b |