diff --git a/ctru-rs/src/lib.rs b/ctru-rs/src/lib.rs index e8c6483..2874839 100644 --- a/ctru-rs/src/lib.rs +++ b/ctru-rs/src/lib.rs @@ -64,6 +64,7 @@ pub mod linear; pub mod mii; pub mod os; pub mod prelude; +mod sealed; pub mod services; pub use crate::error::{Error, Result}; diff --git a/ctru-rs/src/sealed.rs b/ctru-rs/src/sealed.rs new file mode 100644 index 0000000..34d5fee --- /dev/null +++ b/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<'_> {} diff --git a/ctru-rs/src/services/gfx.rs b/ctru-rs/src/services/gfx.rs index 59540cb..7a6ec6e 100644 --- a/ctru-rs/src/services/gfx.rs +++ b/ctru-rs/src/services/gfx.rs @@ -9,30 +9,17 @@ use std::marker::PhantomData; use std::sync::Mutex; use crate::error::Result; +use crate::sealed::Sealed; use crate::services::gspgpu::{self, FramebufferFormat}; 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. /// /// 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 /// trait to work with any of the given screens. #[doc(alias = "gfxScreen_t")] -pub trait Screen: private::Sealed { +pub trait Screen: Sealed { /// Returns the `libctru` value for the Screen kind. 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. /// /// 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. /// /// 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. /// /// 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. /// /// Note that you must still call [`Swap::swap_buffers`] after this method for the buffer contents to be displayed.