Rust-inspired Result/Ok/Err primitives for Python
Project description
rust-ok
Rust-style Result, Ok, and Err primitives for Python projects.
Installation
pip install rust-ok
Usage
from rust_ok import Result, Ok, Err
def parse_int(raw: str) -> Result[int, str]:
try:
return Ok(int(raw))
except ValueError as exc:
return Err(str(exc))
result = parse_int("42")
print(result.unwrap_or(0)) # -> 42
Formatting exception chains
from rust_ok import Err, Ok, format_exception_chain
try:
Err(ValueError("boom")).unwrap()
except Exception as exc:
print(format_exception_chain(exc))
Iterating over results
from rust_ok import Err, Ok, is_ok
results = [Ok(1), Err("bad"), Ok(3)]
for res in results:
if is_ok(res):
print("value:", res.unwrap())
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file rust_ok-0.2.2.tar.gz.
File metadata
- Download URL: rust_ok-0.2.2.tar.gz
- Upload date:
- Size: 5.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
420a3b55151f8506bdef14db4036e1c9747786fabf3f0d2d8c0f0e4cd0348474
|
|
| MD5 |
ea6cb9304673e9d4e1a6217c368c1cd0
|
|
| BLAKE2b-256 |
4bd81316ea15a56650f6dd971b1e385175e500dcca09b36149d2c53f6d4f1bb7
|
Provenance
The following attestation bundles were made for rust_ok-0.2.2.tar.gz:
Publisher:
release.yaml on pesap/rust-ok
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
rust_ok-0.2.2.tar.gz -
Subject digest:
420a3b55151f8506bdef14db4036e1c9747786fabf3f0d2d8c0f0e4cd0348474 - Sigstore transparency entry: 832458173
- Sigstore integration time:
-
Permalink:
pesap/rust-ok@06003268bf12440656beb7b632b70cfea1b898d8 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/pesap
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yaml@06003268bf12440656beb7b632b70cfea1b898d8 -
Trigger Event:
push
-
Statement type:
File details
Details for the file rust_ok-0.2.2-py3-none-any.whl.
File metadata
- Download URL: rust_ok-0.2.2-py3-none-any.whl
- Upload date:
- Size: 7.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
93fa556ce8f44b8c2bc8a3964bcdf8b7231773c50b51e221286b83d29ee3b9d7
|
|
| MD5 |
2773061f76a5f1bd6f45a3b2dd3fa9e4
|
|
| BLAKE2b-256 |
0e5529444a8895d9bf7bccf2ac9929cc13402facfd16869ee260cefb511703cb
|
Provenance
The following attestation bundles were made for rust_ok-0.2.2-py3-none-any.whl:
Publisher:
release.yaml on pesap/rust-ok
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
rust_ok-0.2.2-py3-none-any.whl -
Subject digest:
93fa556ce8f44b8c2bc8a3964bcdf8b7231773c50b51e221286b83d29ee3b9d7 - Sigstore transparency entry: 832458174
- Sigstore integration time:
-
Permalink:
pesap/rust-ok@06003268bf12440656beb7b632b70cfea1b898d8 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/pesap
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yaml@06003268bf12440656beb7b632b70cfea1b898d8 -
Trigger Event:
push
-
Statement type: