Skip to main content

Rust-like fielded Enums in Python

Project description

fieldenum

PyPI - Downloads Hits Coverage Status Sponsoring

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


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.2.0.tar.gz (9.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

fieldenum-0.2.0-py3-none-any.whl (9.8 kB view details)

Uploaded Python 3

File details

Details for the file fieldenum-0.2.0.tar.gz.

File metadata

  • Download URL: fieldenum-0.2.0.tar.gz
  • Upload date:
  • Size: 9.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.12.5 Windows/11

File hashes

Hashes for fieldenum-0.2.0.tar.gz
Algorithm Hash digest
SHA256 7997d97154b86fd2fed3df9951539cb2b9ae4b26f38f71185fdea98423a3ada2
MD5 ef05aa0bebb1e582fa5d39e5c96f6b0b
BLAKE2b-256 0a8e546e898513bda0b3f7b6e90288e0e0e4c0f067ca5e1dd77319c047598b84

See more details on using hashes here.

File details

Details for the file fieldenum-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: fieldenum-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 9.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.12.5 Windows/11

File hashes

Hashes for fieldenum-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ec5a6b12f463fb8769530794016054b9b7990206f9e2ecec1c6e11ab94353a8b
MD5 0f8474299a37b20561a07a6df544480f
BLAKE2b-256 71b6008ce14dd5429a1133ac253ce1de7aabdc6f4fcfab4e589802c45a66bb86

See more details on using hashes here.

Supported by

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