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.1.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.1-py3-none-any.whl (7.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: rust_ok-0.2.1.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.1.tar.gz
Algorithm Hash digest
SHA256 e4a7ce721f3a70ecaf9efa0c87a31d342e89feff1026874afae3b3ac30851755
MD5 4b6dba866c3f28b220b12253b3a210a3
BLAKE2b-256 1c5002edeefcb33228b043d417b2fd25688decb1a365a9b0773f099049b24edb

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: rust_ok-0.2.1-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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 873a8e05deaa3c0104240f246cd498823a12675a280bf2311d80bec93d96edb6
MD5 0346427ae08ece70c4a16740e82303f3
BLAKE2b-256 ee5c8182c10ed4c3339d2627c9477b6daf1f1d06de1a7998bb5830ff673f2d4a

See more details on using hashes here.

Provenance

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