This is an automated archive made by the Lemmit Bot.

The original was posted on /r/rust by /u/rustological on 2023-08-11 16:02:37.


One way to call methodA or methodB, if depending on different platforms, is via conditional compilation For example, compilation on Windows and Linux requires different handling of filenames/paths. Ok, makes sense, like with C.

However, how to implement a dynamic choice on startup? Say, I’m running Linux, and either in a terminal/TUI or under X/GUI. On startup I have to run some checking code first, and then I want to set “output a string so user surely sees it” needs to be either writeTUI(…) oder writeGUI(…), globally, throughout the rest of the program.

Trait of methods with variants, then specific trait object instance assigned to global accessible static after test at startup?