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.2.0.tar.gz (5.0 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.2.0-py3-none-any.whl (7.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: rust_ok-0.2.0.tar.gz
  • Upload date:
  • Size: 5.0 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.2.0.tar.gz
Algorithm Hash digest
SHA256 746657212646531e110f00a088ff37d6acd001e7e61ba4eb419608e76e828478
MD5 4691f81670bb6eb774391f784dfd85e3
BLAKE2b-256 198fe643edeb4dea1b4d81608dfc74b8167cd75b5b3480f2b61825967f2563d3

See more details on using hashes here.

Provenance

The following attestation bundles were made for rust_ok-0.2.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.2.0-py3-none-any.whl.

File metadata

  • Download URL: rust_ok-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 7.0 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.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 41bec094856ada5ac0b8001e0833ad9bb3002d9e55153f3201dda933f8652812
MD5 48f1c4b8086ec2665a7374ffffcaa515
BLAKE2b-256 3cf648495688584487d1223df5934ea9c0a7ca1717a68f0aa853821acd19ad82

See more details on using hashes here.

Provenance

The following attestation bundles were made for rust_ok-0.2.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