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 hashes)
Built Distribution
optres-0.1.0-py3-none-any.whl
(7.5 kB
view hashes)