Rust-style enums
Project description
Rust-style enums for Python
Easily-defined enumerations that can contain data and be matched.
Here they are:
from rust_enum import enum, Case
def test_enum_use_case():
@enum
class DivisionResult:
Undefined = Case()
Some = Case(number=float)
def divide(a: float, b: float) -> DivisionResult:
if b == 0: return DivisionResult.Undefined()
return DivisionResult.Some(a / b)
match divide(3, 3):
case DivisionResult.Some(n): assert n == 1
case _: assert False
Installation
pip install rust_enum
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_enum-1.1.0.tar.gz
(2.3 kB
view hashes)
Built Distribution
Close
Hashes for rust_enum-1.1.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ed7955bfe316ad26ca60ba7fc89e7f30df635ac18e999accc64a5fa10520cead |
|
MD5 | 53a11a0c4fc37be0e6db47aafbd21545 |
|
BLAKE2b-256 | cbec10200907d9163d95ccfe6f63b33b3dd92d5c9463cb458189d4dd9d0f87c2 |