Skip to main content

Rust-like fielded Enum in Python

Project description

fieldenum

Rust-like fielded Enum in Python

Examples

from fieldenum import fieldenum, Item

# define
@fieldenum
class Message:
    Quit = Item()
    Move = Item(x=int, y=int)
    Write = Item(str)
    ChangeColor = Item(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.

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

fieldenum-0.0.1.tar.gz (1.2 kB view hashes)

Uploaded Source

Built Distribution

fieldenum-0.0.1-py3-none-any.whl (1.5 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page