Skip to main content

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

rust_ok-0.3.0.tar.gz (5.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

rust_ok-0.3.0-py3-none-any.whl (7.3 kB view details)

Uploaded Python 3

File details

Details for the file rust_ok-0.3.0.tar.gz.

File metadata

  • Download URL: rust_ok-0.3.0.tar.gz
  • Upload date:
  • Size: 5.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for rust_ok-0.3.0.tar.gz
Algorithm Hash digest
SHA256 7d79997d87b31fa8d960180ecb3abb2c989c6294c65ffad642963baf5da21447
MD5 352cb76f14a6ab241795ea578c28f5a0
BLAKE2b-256 d4b487573f97dfecc11158ac35e8cb57045dc8759c51b56010a1423194481cdc

See more details on using hashes here.

Provenance

The following attestation bundles were made for rust_ok-0.3.0.tar.gz:

Publisher: release.yaml on pesap/rust-ok

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file rust_ok-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: rust_ok-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 7.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for rust_ok-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4b1635c0623c1a3a3f039a739fd47271bcdb4b5f4fc4fc833e70d197708d65c5
MD5 f6f7eba9cd7c79438ebe7c6b341d6717
BLAKE2b-256 456a606fc68d1d16725915832577bf0fe62621dbb0dcc931cd5b4bade72e9099

See more details on using hashes here.

Provenance

The following attestation bundles were made for rust_ok-0.3.0-py3-none-any.whl:

Publisher: release.yaml on pesap/rust-ok

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page