You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The Backend trait contract returns Option<&str> in version 2.0, however the README shows the example of the RemoveI18n that returns Option instead.
Currently I'm trying to create a "reloadable backend". where I can setup a watcher via the Notify create to reload the translations from disk. However I am running into issues due to the contract change of Backend as I am unable to return a reference to a string.
structReloadableBackend{translations:Arc<RwLock<HashMap<String,HashMap<String,String>>>>,}implBackendforReloadableBackend{fnavailable_locales(&self) -> Vec<&str>{let l = self.i18n.read();ifletOk(h) = l {letmut locales = h.keys().map(|k| k.as_str()).collect::<Vec<_>>();
locales.sort();
locales // Error cannot return value referencing local variable `h` [E0515] returns a value referencing data owned by the current function}else{Vec::new()}}fntranslate(&self,locale:&str,key:&str) -> Option<&'_ str>{let l = self.i18n.read();ifletOk(h) = l {return h
.get(locale).and_then(|trs| trs.get(key)).and_then(|k| Some(k.as_str()));// cannot return value referencing local variable `h` [E0515] returns a value referencing data owned by the current function}else{None}}}
This, of course, makes perfect sense since it has to return a reference from the locked data in the Arc.
If the contract were still returning String then this would not be an issue as I could just return a cloned string and move on.
The text was updated successfully, but these errors were encountered:
The Backend trait contract returns Option<&str> in version 2.0, however the README shows the example of the RemoveI18n that returns Option instead.
Currently I'm trying to create a "reloadable backend". where I can setup a watcher via the Notify create to reload the translations from disk. However I am running into issues due to the contract change of Backend as I am unable to return a reference to a string.
This, of course, makes perfect sense since it has to return a reference from the locked data in the Arc.
If the contract were still returning String then this would not be an issue as I could just return a cloned string and move on.
The text was updated successfully, but these errors were encountered: