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.1.0.tar.gz (4.6 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.1.0-py3-none-any.whl (6.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: rust_ok-0.1.0.tar.gz
  • Upload date:
  • Size: 4.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.10 {"installer":{"name":"uv","version":"0.9.10"},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for rust_ok-0.1.0.tar.gz
Algorithm Hash digest
SHA256 65061f2720da9668ac773d41c1bbb26c136ac44ae64825fcc30ded7da906304c
MD5 6d48ab6ea8a1dc000c945b1d6fc836ad
BLAKE2b-256 97e4d4ba4f6371bb3d2aa43e755bbba1c826e04250dbe21d0bbc31118762171c

See more details on using hashes here.

File details

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

File metadata

  • Download URL: rust_ok-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 6.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.10 {"installer":{"name":"uv","version":"0.9.10"},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for rust_ok-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 1d5798151644a26a1ae1140dece1494f632f017b9eff8fb1c43feb9a7b9c1223
MD5 bb4c0e68b3aed680109010cfb7dbf25d
BLAKE2b-256 c12d0d77828ee2d53d3d7255027243d6544dc79611564383ac372bf61ed5132d

See more details on using hashes here.

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