fieldenum
Rust-like fielded Enums in Python
Examples
from fieldenum import fieldenum, Unit, Variant
@fieldenum
class Message:
Quit = Unit
Move = Variant(x=int, y=int)
Write = Variant(str)
ChangeColor = Variant(int, int, int)
# Corresponding code in Rust:
# enum Message {
# Quit,
# Move { x: i32, y: i32 },
# Write(String),
# ChangeColor(i32, i32, i32),
# }
# usage
message = Message.Quit
message = Message.Move(x=1, y=2)
message = Message.Write("hello, world!")
message = Message.ChangeColor(256, 256, 0)
Credits
This project is heavily influenced by Rust's Enum, and also borrows some of its design from rust_enum.
Releases
- 0.1.0: initial release
Metadata
Release files for fieldenum 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| fieldenum-0.2.0.tar.gz | 9.2 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| fieldenum-0.2.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 19.0 kB
Release files / fieldenum-0.2.0.tar.gz
| Download URL | fieldenum-0.2.0.tar.gz |
|---|---|
| Size | 9.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
7997d97154b86fd2fed3df9951539cb2b9ae4b26f38f71185fdea98423a3ada2
|
|
BLAKE2b-256 checksum How to use checksums |
0a8e546e898513bda0b3f7b6e90288e0e0e4c0f067ca5e1dd77319c047598b84
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.8.3 CPython/3.12.5 Windows/11
|
Release files / fieldenum-0.2.0-py3-none-any.whl
| Download URL | fieldenum-0.2.0-py3-none-any.whl |
|---|---|
| Size | 9.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
ec5a6b12f463fb8769530794016054b9b7990206f9e2ecec1c6e11ab94353a8b
|
|
BLAKE2b-256 checksum How to use checksums |
71b6008ce14dd5429a1133ac253ce1de7aabdc6f4fcfab4e589802c45a66bb86
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.8.3 CPython/3.12.5 Windows/11
|