Rsult
Rsult (rust result = rs + result) is a python library for adding rust like
Result[T, E]support to python.
Background
In rust, rather than throw exceptions up some side channel, you return them directly as part of a functions response.
These responses are wrapped in what rust refers to as a Result.
Result's are simple objects which contain either the result of the function call, or an exception which was raised by the function.
Usage
There are many ways you can choose to use the rsult Result class.
The most common use is to just unpack the response into individual error and response variables.
However, the unwrap() functio can also be used much like unwrap in rust.
When called from a result that does not contain an error, unwrap(result) will return the response from the function.
If unwrap(result) is called with a result that contains an error, that error will be raised as an exception.
Examples
from rsult import Result, unwrap, wrap, wrap_error
class LessThanZeroError(Exception):
pass
def add_numbers(x: int, y: int) -> Result[int, LessThanZeroError]:
z = x + y
if z < 0:
return wrap_error(LessThanZeroError())
return wrap(z)
# a regular call to the function that returns the response
error, answer = add_numbers(2, 2)
assert error is None
assert answer == 4
# a call to the function that results in an error
error, answer = add_numbers(2, -4)
assert type(error) is LessThanZeroError
assert answer is None
# unwrap can be used to throw the error, rather than unpacking the result
result = add_numbers(2, -4)
answer = unwrap(result) # <-- LessThanZeroError gets throw
Authors
Metadata
Release files for rsult 1.0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| rsult-1.0.1.tar.gz | 19.5 kB | Without provenance | Details for rsult-1.0.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| rsult-1.0.1-py3-none-any.whl | Python 3 | none | any | Details for rsult-1.0.1-py3-none-any.whl |
Total release size: 22.6 kB
Release files / rsult-1.0.1.tar.gz
| Download URL | rsult-1.0.1.tar.gz |
|---|---|
| Size | 19.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
a6e7535a8189261f6803cab67b3da1319f26594e5d918ce236a1e702b4689aca
|
|
BLAKE2b-256 checksum How to use checksums |
4ca68251b45f1fc1219d9d73b156db6e9009e98f2028d2cb9bc18c40f3a347c1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.6.3
|
Release files / rsult-1.0.1-py3-none-any.whl
| Download URL | rsult-1.0.1-py3-none-any.whl |
|---|---|
| Size | 3.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
5cb20f0c3232576a4aacd8898172a3e841aa932b706411fadbe7740d2ec11f60
|
|
BLAKE2b-256 checksum How to use checksums |
2fe8a10f5ee2fd92f41dc03dea59f753ce2cd59a41b0bc695ebb50e671de3ddc
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.6.3
|
Security for rsult 1.0.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.