-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Description
Hi, in my iced app I use a localization system to translate options inside pick lists. However, Picklist only relies on the toString trait to display its options. So for the translation to happen, my Display trait implementation must check a global variable at each call:
impl Display for Armor {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", self.apply_locale(&*crate::LOCALE.lock().unwrap()))
}
}LOCALE is the global variable (I use once_cell). In my opinion, this is not very pretty to check a global variable inside an implementation of such a trait.
There is another limitation, I can't implement the Display trait for a Struct from an external crate. What I would like is to be able to give a closure to the PickList struct to handle converting options into String (maybe Fn(T) -> String or another trait like PickListDisplay?).
Is this possible? I could try implementing it if you think this is. Thank you for maintaining iced by the way.