Browse Source

Move Sealed to separate file

pull/86/head
AzureMarker 12 months ago
parent
commit
1496d47ef2
  1. 1
      ctru-rs/src/lib.rs
  2. 15
      ctru-rs/src/sealed.rs
  3. 21
      ctru-rs/src/services/gfx.rs

1
ctru-rs/src/lib.rs

@ -64,6 +64,7 @@ pub mod linear;
pub mod mii; pub mod mii;
pub mod os; pub mod os;
pub mod prelude; pub mod prelude;
mod sealed;
pub mod services; pub mod services;
pub use crate::error::{Error, Result}; pub use crate::error::{Error, Result};

15
ctru-rs/src/sealed.rs

@ -0,0 +1,15 @@
//! This is a private module to prevent users from implementing certain traits.
//! This is done by requiring a `Sealed` trait implementation, which can only be
//! done in this crate.
use crate::console::Console;
use crate::services::gfx::{BottomScreen, TopScreen, TopScreen3D, TopScreenLeft, TopScreenRight};
pub trait Sealed {}
impl Sealed for TopScreen {}
impl Sealed for TopScreen3D<'_> {}
impl Sealed for TopScreenLeft {}
impl Sealed for TopScreenRight {}
impl Sealed for BottomScreen {}
impl Sealed for Console<'_> {}

21
ctru-rs/src/services/gfx.rs

@ -9,30 +9,17 @@ use std::marker::PhantomData;
use std::sync::Mutex; use std::sync::Mutex;
use crate::error::Result; use crate::error::Result;
use crate::sealed::Sealed;
use crate::services::gspgpu::{self, FramebufferFormat}; use crate::services::gspgpu::{self, FramebufferFormat};
use crate::services::ServiceReference; use crate::services::ServiceReference;
mod private {
use super::{BottomScreen, TopScreen, TopScreen3D, TopScreenLeft, TopScreenRight};
use crate::console::Console;
pub trait Sealed {}
impl Sealed for TopScreen {}
impl Sealed for TopScreen3D<'_> {}
impl Sealed for TopScreenLeft {}
impl Sealed for TopScreenRight {}
impl Sealed for BottomScreen {}
impl Sealed for Console<'_> {}
}
/// Trait to handle common functionality for all screens. /// Trait to handle common functionality for all screens.
/// ///
/// This trait is implemented by the screen structs for working with frame buffers and /// This trait is implemented by the screen structs for working with frame buffers and
/// drawing to the screens. Graphics-related code can be made generic over this /// drawing to the screens. Graphics-related code can be made generic over this
/// trait to work with any of the given screens. /// trait to work with any of the given screens.
#[doc(alias = "gfxScreen_t")] #[doc(alias = "gfxScreen_t")]
pub trait Screen: private::Sealed { pub trait Screen: Sealed {
/// Returns the `libctru` value for the Screen kind. /// Returns the `libctru` value for the Screen kind.
fn as_raw(&self) -> ctru_sys::gfxScreen_t; fn as_raw(&self) -> ctru_sys::gfxScreen_t;
@ -101,7 +88,7 @@ pub struct TopScreen3D<'screen> {
/// Trait for screens that can have its frame buffers swapped, when double buffering is enabled. /// Trait for screens that can have its frame buffers swapped, when double buffering is enabled.
/// ///
/// This trait applies to all [`Screen`]s that have swappable frame buffers. /// This trait applies to all [`Screen`]s that have swappable frame buffers.
pub trait Swap: private::Sealed { pub trait Swap: Sealed {
/// Swaps the video buffers. /// Swaps the video buffers.
/// ///
/// Even if double buffering is disabled, "swapping" the buffers has the side effect /// Even if double buffering is disabled, "swapping" the buffers has the side effect
@ -162,7 +149,7 @@ impl Swap for BottomScreen {
/// A screen with buffers that can be flushed. /// A screen with buffers that can be flushed.
/// ///
/// This trait applies to any [`Screen`] that has data written to its frame buffer. /// This trait applies to any [`Screen`] that has data written to its frame buffer.
pub trait Flush: private::Sealed { pub trait Flush: Sealed {
/// Flushes the video buffer(s) for this screen. /// Flushes the video buffer(s) for this screen.
/// ///
/// Note that you must still call [`Swap::swap_buffers`] after this method for the buffer contents to be displayed. /// Note that you must still call [`Swap::swap_buffers`] after this method for the buffer contents to be displayed.

Loading…
Cancel
Save