Skip to content

Commit

Permalink
Revert "Add conversions between Visibility and bool (bevyengine#14784)…
Browse files Browse the repository at this point in the history
…" (bevyengine#14830)

This reverts commit e37bf18, added in
bevyengine#14784.

# Objective

The PR was fine, but the work was very poorly motivated and the
resulting API is not actually very nice. The actual user need is likely
better addressed by bevyengine#14825.

## Solution

Revert the offending PR.
  • Loading branch information
alice-i-cecile committed Aug 20, 2024
1 parent 99ab028 commit ba28479
Showing 1 changed file with 0 additions and 39 deletions.
39 changes: 0 additions & 39 deletions crates/bevy_render/src/view/visibility/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ use crate::{
primitives::{Aabb, Frustum, Sphere},
};

use thiserror::Error;

use super::NoCpuCulling;

/// User indication of whether an entity is visible. Propagates down the entity hierarchy.
Expand All @@ -49,43 +47,6 @@ pub enum Visibility {
Visible,
}

/// Enum of errors that could occur during conversion to [`bool`]
#[non_exhaustive]
#[derive(Error, Debug)]
pub enum VisibilityToBoolConversionError {
#[error("The variant `{0:?}` cannot be converted to a bool")]
VariantNotSupported(Visibility),
}
/// Implements conversion from bool to Visibility
/// `true` corresponds to [`Visibility::Visible`], while false corresponds to [`Visibility::Hidden`].
impl From<bool> for Visibility {
fn from(visible: bool) -> Visibility {
if visible {
Visibility::Visible
} else {
Visibility::Hidden
}
}
}

/// Implements conversion from [`Visibility`] to [`bool`]
/// - returns `Ok(true)` if `Visibility::Visible`
/// - returns `Ok(false)` if `Visibility::Hidden`
/// - returns `Err()` if `Visibility::Inherited`
impl TryFrom<Visibility> for bool {
type Error = VisibilityToBoolConversionError;

fn try_from(visible: Visibility) -> Result<Self, Self::Error> {
match visible {
Visibility::Hidden => Ok(false),
Visibility::Visible => Ok(true),
Visibility::Inherited => Err(VisibilityToBoolConversionError::VariantNotSupported(
Visibility::Inherited,
)),
}
}
}

// Allows `&Visibility == Visibility`
impl PartialEq<Visibility> for &Visibility {
#[inline]
Expand Down

0 comments on commit ba28479

Please sign in to comment.