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.2.tar.gz (5.2 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.2-py3-none-any.whl (7.2 kB view details)

Uploaded Python 3

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

Hashes for rust_ok-0.2.2.tar.gz
Algorithm Hash digest
SHA256 420a3b55151f8506bdef14db4036e1c9747786fabf3f0d2d8c0f0e4cd0348474
MD5 ea6cb9304673e9d4e1a6217c368c1cd0
BLAKE2b-256 4bd81316ea15a56650f6dd971b1e385175e500dcca09b36149d2c53f6d4f1bb7

See more details on using hashes here.

Provenance

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

Hashes for rust_ok-0.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 93fa556ce8f44b8c2bc8a3964bcdf8b7231773c50b51e221286b83d29ee3b9d7
MD5 2773061f76a5f1bd6f45a3b2dd3fa9e4
BLAKE2b-256 0e5529444a8895d9bf7bccf2ac9929cc13402facfd16869ee260cefb511703cb

See more details on using hashes here.

Provenance

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