enums

Using enums for dynamic polymorphism in Rust

旧时模样 提交于 2020-11-28 08:28:06
问题 When one already knows all the finite number of types involved in some code which needs dynamic polymorphism, using enum can be better for performances compared to using Box since the latter uses dynamic memory allocation and you'll need to use trait objects which have virtual function call as well. That said, compared to the equivalent code in C++ using std::variant and std::visit , looks like Rust in this scenario has more boilerplate coding involved, at least for me (I have not yet learned

how to serialise a enum property in sqlalchemy using marshmallow

蹲街弑〆低调 提交于 2020-11-28 04:54:21
问题 this is my model class class Type(enum.Enum): Certified = "certified" Non_Certified = "non-certified" class Status(enum.Enum): Approved = "Approved" Rejected = "Rejected" Published = "Published" Retired = "Retired" Waiting_for_Approval = "Waiting_for_Approval" class DifficultyLevel(enum.Enum): Beginner = "Beginner" Intermediate = "Intermediate" Advanced = "Advanced" All = "All" class ActiveStatus(enum.Enum): Archive = "archive" Restore = "restore" class Course(Base): __tablename__ = 'course'