Skip to content

Commit

Permalink
impl Not for &Visibility
Browse files Browse the repository at this point in the history
accept suggestion to use `matches!`
  • Loading branch information
ickk committed Oct 18, 2022
1 parent 830c0d9 commit 4b90066
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions crates/bevy_render/src/view/visibility/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use bevy_reflect::Reflect;
use bevy_transform::components::GlobalTransform;
use bevy_transform::TransformSystem;
use std::cell::Cell;
use std::ops::Not;
use thread_local::ThreadLocal;

use crate::{
Expand Down Expand Up @@ -39,23 +40,29 @@ impl Default for Visibility {
}
}

impl Not for &Visibility {
type Output = Visibility;

#[inline]
fn not(self) -> Visibility {
match self {
Visibility::Shown => Visibility::Hidden,
Visibility::Hidden => Visibility::Shown,
}
}
}

impl Visibility {
/// Whether this entity is visible.
#[inline]
pub const fn is_visible(&self) -> bool {
match self {
Self::Shown => true,
Self::Hidden => false,
}
matches!(self, Self::Shown)
}

/// Toggle the visibility.
#[inline]
pub fn toggle(&mut self) {
*self = match self {
Self::Shown => Self::Hidden,
Self::Hidden => Self::Shown,
}
*self = !&*self
}
}

Expand Down

0 comments on commit 4b90066

Please sign in to comment.