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
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.0.1.tar.gz
(1.8 kB
view hashes)
Built Distribution
Close
Hashes for rust_enum-1.0.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 15f75e9b7ca70879c0c96ef78e89df07234c1c639d9e80b5bc25093189a88430 |
|
MD5 | ff16c8e7bda9a47b423f8a45d4aa0b20 |
|
BLAKE2b-256 | 049490d36f5572832be425c5f706e46c5e1bc8c1b4d9332c05bcb18685116994 |