Rust-like fielded Enums in Python
Project description
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
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
fieldenum-0.1.0.tar.gz
(7.5 kB
view hashes)
Built Distribution
Close
Hashes for fieldenum-0.1.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d32bfc9238e264e3bfff03aec9e85d0d7b40e05577a55fcd8779d9d4608776e0 |
|
MD5 | 1fb46c8c32474182f44dc7d3d88a7bc2 |
|
BLAKE2b-256 | 72e7101337275901ac246f5fe64c7c5b7dd925d3bfc1b3fd2df0f4d4b7b8242e |