Use try_global()

This commit is contained in:
Joseph T. Lyons 2024-01-18 00:58:50 -05:00
parent 933fb87013
commit b807e6fe80
10 changed files with 52 additions and 70 deletions

View file

@ -57,18 +57,14 @@ impl FeatureFlagAppExt for AppContext {
}
fn has_flag<T: FeatureFlag>(&self) -> bool {
if self.has_global::<FeatureFlags>() {
self.global::<FeatureFlags>().has_flag(T::NAME)
} else {
false
}
self.try_global::<FeatureFlags>()
.map(|flags| flags.has_flag(T::NAME))
.unwrap_or(false)
}
fn is_staff(&self) -> bool {
if self.has_global::<FeatureFlags>() {
return self.global::<FeatureFlags>().staff;
} else {
false
}
self.try_global::<FeatureFlags>()
.map(|flags| flags.staff)
.unwrap_or(false)
}
}