Embedding API: prefs r/w

This commit is contained in:
Paul Rouget 2020-06-05 14:03:31 +02:00
parent 7df4655b60
commit 479afcfb8e
10 changed files with 460 additions and 157 deletions

View file

@ -220,6 +220,17 @@ impl<'m, P: Clone> Preferences<'m, P> {
}
}
/// Has the preference been modified from its original value?
pub fn is_default(&self, key: &str) -> Result<bool, PrefError> {
if let Some(accessor) = self.accessors.get(key) {
let user = (accessor.getter)(&self.default_prefs);
let default = (accessor.getter)(&self.user_prefs.read().unwrap());
Ok(default == user)
} else {
Err(PrefError::NoSuchPref(String::from(key)))
}
}
/// Creates an iterator over all keys and values
pub fn iter<'a>(&'a self) -> impl Iterator<Item = (String, PrefValue)> + 'a {
let prefs = self.user_prefs.read().unwrap();