Skip to content

Commit 4b90066

Browse files
committed
impl Not for &Visibility
accept suggestion to use `matches!`
1 parent 830c0d9 commit 4b90066

File tree

1 file changed

+15
-8
lines changed
  • crates/bevy_render/src/view/visibility

1 file changed

+15
-8
lines changed

crates/bevy_render/src/view/visibility/mod.rs

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ use bevy_reflect::Reflect;
1111
use bevy_transform::components::GlobalTransform;
1212
use bevy_transform::TransformSystem;
1313
use std::cell::Cell;
14+
use std::ops::Not;
1415
use thread_local::ThreadLocal;
1516

1617
use crate::{
@@ -39,23 +40,29 @@ impl Default for Visibility {
3940
}
4041
}
4142

43+
impl Not for &Visibility {
44+
type Output = Visibility;
45+
46+
#[inline]
47+
fn not(self) -> Visibility {
48+
match self {
49+
Visibility::Shown => Visibility::Hidden,
50+
Visibility::Hidden => Visibility::Shown,
51+
}
52+
}
53+
}
54+
4255
impl Visibility {
4356
/// Whether this entity is visible.
4457
#[inline]
4558
pub const fn is_visible(&self) -> bool {
46-
match self {
47-
Self::Shown => true,
48-
Self::Hidden => false,
49-
}
59+
matches!(self, Self::Shown)
5060
}
5161

5262
/// Toggle the visibility.
5363
#[inline]
5464
pub fn toggle(&mut self) {
55-
*self = match self {
56-
Self::Shown => Self::Hidden,
57-
Self::Hidden => Self::Shown,
58-
}
65+
*self = !&*self
5966
}
6067
}
6168

0 commit comments

Comments
 (0)