Use try_global()
This commit is contained in:
parent
933fb87013
commit
b807e6fe80
10 changed files with 52 additions and 70 deletions
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue