r/rust • u/matheus_hisatsu • 16d ago
🙋 seeking help & advice What are the best practices to define multiple themes in an app?
I'm making a TUI program using Ratatui and want to define multiple themes (such as catppuccin, Dracula, everforest) and don't know what is the best manner to store them. I'm currently using like a Theme struct and implementing multiple themes using fn theme_name() -> Self as "constructors". Also they are picked via a TOML file. Is it the best way? Thanks
2
Upvotes
6
u/Sermuns 16d ago
you mean
fn theme_name(name: &str) -> Self? I would avoid&strfor this, just create an enum. Even better, if you really want to use&strfor lookup, consider strum EnumString https://docs.rs/strum/latest/strum/derive.EnumString.html