From c6d8d8823f63b82784f6db49e8108582c465091d Mon Sep 17 00:00:00 2001 From: AzureMarker Date: Tue, 26 Dec 2023 12:35:40 -0500 Subject: [PATCH] Remove Console S generic by making ConsoleScreen trait alias --- ctru-rs/examples/file-explorer.rs | 3 +-- ctru-rs/examples/ir-user-circle-pad-pro.rs | 11 ++++------- ctru-rs/src/console.rs | 18 +++++++++++------- ctru-rs/src/services/gfx.rs | 4 ++-- 4 files changed, 18 insertions(+), 18 deletions(-) diff --git a/ctru-rs/examples/file-explorer.rs b/ctru-rs/examples/file-explorer.rs index 0c2b595..3ad37c9 100644 --- a/ctru-rs/examples/file-explorer.rs +++ b/ctru-rs/examples/file-explorer.rs @@ -6,7 +6,6 @@ use ctru::applets::swkbd::{Button, SoftwareKeyboard}; use ctru::prelude::*; -use ctru::services::gfx::TopScreen; use std::fs::DirEntry; use std::os::horizon::fs::MetadataExt; use std::path::{Path, PathBuf}; @@ -27,7 +26,7 @@ struct FileExplorer<'a> { apt: &'a Apt, hid: &'a mut Hid, gfx: &'a Gfx, - console: Console<'a, TopScreen>, + console: Console<'a>, path: PathBuf, entries: Vec, running: bool, diff --git a/ctru-rs/examples/ir-user-circle-pad-pro.rs b/ctru-rs/examples/ir-user-circle-pad-pro.rs index 10fa58d..bdb88cb 100644 --- a/ctru-rs/examples/ir-user-circle-pad-pro.rs +++ b/ctru-rs/examples/ir-user-circle-pad-pro.rs @@ -1,7 +1,7 @@ //! A demo of using the ir:USER service to connect to the Circle Pad Pro. use ctru::prelude::*; -use ctru::services::gfx::{BottomScreen, Flush, Swap, TopScreen}; +use ctru::services::gfx::{Flush, Swap}; use ctru::services::ir_user::{CirclePadProInputResponse, ConnectionStatus, IrDeviceId, IrUser}; use ctru::services::srv::HandleExt; use ctru_sys::Handle; @@ -62,8 +62,8 @@ fn main() { } struct CirclePadProDemo<'screen> { - top_console: Console<'screen, TopScreen>, - bottom_console: Console<'screen, BottomScreen>, + top_console: Console<'screen>, + bottom_console: Console<'screen>, ir_user: IrUser, connection_status_event: Handle, receive_packet_event: Handle, @@ -75,10 +75,7 @@ enum ConnectionResult { } impl<'screen> CirclePadProDemo<'screen> { - fn new( - mut top_console: Console<'screen, TopScreen>, - bottom_console: Console<'screen, BottomScreen>, - ) -> Self { + fn new(mut top_console: Console<'screen>, bottom_console: Console<'screen>) -> Self { // Set up double buffering on top screen top_console.set_double_buffering(true); top_console.swap_buffers(); diff --git a/ctru-rs/src/console.rs b/ctru-rs/src/console.rs index 78e8840..cb98840 100644 --- a/ctru-rs/src/console.rs +++ b/ctru-rs/src/console.rs @@ -39,6 +39,10 @@ pub enum Dimension { Height, } +/// A [`Screen`] that can be used as a target for [`Console`]. +pub trait ConsoleScreen: Screen + Swap + Flush {} +impl ConsoleScreen for S {} + /// Virtual text console. /// /// [`Console`] lets the application redirect `stdout` and `stderr` to a simple text displayer on the 3DS screen. @@ -58,12 +62,12 @@ pub enum Dimension { /// you can try using [`Soc::redirect_to_3dslink`](crate::services::soc::Soc::redirect_to_3dslink) while activating the `--server` flag for `3dslink` (also supported by `cargo-3ds`). /// More info in the [`cargo-3ds` docs](https://github.com/rust3ds/cargo-3ds#running-executables). #[doc(alias = "PrintConsole")] -pub struct Console<'screen, S: Screen> { +pub struct Console<'screen> { context: Box, - screen: RefMut<'screen, S>, + screen: RefMut<'screen, dyn ConsoleScreen>, } -impl<'screen, S: Screen> Console<'screen, S> { +impl<'screen> Console<'screen> { /// Initialize a console on the chosen screen. /// /// # Notes @@ -102,7 +106,7 @@ impl<'screen, S: Screen> Console<'screen, S> { /// # } /// ``` #[doc(alias = "consoleInit")] - pub fn new(screen: RefMut<'screen, S>) -> Self { + pub fn new(screen: RefMut<'screen, S>) -> Self { let mut context = Box::::default(); unsafe { consoleInit(screen.as_raw(), context.as_mut()) }; @@ -324,7 +328,7 @@ impl<'screen, S: Screen> Console<'screen, S> { } } -impl Swap for Console<'_, S> { +impl Swap for Console<'_> { /// Swaps the video buffers. Note: The console's cursor position is not reset, only the framebuffer is changed. /// /// Even if double buffering is disabled, "swapping" the buffers has the side effect @@ -342,13 +346,13 @@ impl Swap for Console<'_, S> { } } -impl Flush for Console<'_, S> { +impl Flush for Console<'_> { fn flush_buffers(&mut self) { self.screen.flush_buffers(); } } -impl Drop for Console<'_, S> { +impl Drop for Console<'_> { fn drop(&mut self) { unsafe { // Safety: We are about to deallocate the PrintConsole data pointed diff --git a/ctru-rs/src/services/gfx.rs b/ctru-rs/src/services/gfx.rs index 2420842..59540cb 100644 --- a/ctru-rs/src/services/gfx.rs +++ b/ctru-rs/src/services/gfx.rs @@ -13,7 +13,7 @@ use crate::services::gspgpu::{self, FramebufferFormat}; use crate::services::ServiceReference; mod private { - use super::{BottomScreen, Screen, TopScreen, TopScreen3D, TopScreenLeft, TopScreenRight}; + use super::{BottomScreen, TopScreen, TopScreen3D, TopScreenLeft, TopScreenRight}; use crate::console::Console; pub trait Sealed {} @@ -23,7 +23,7 @@ mod private { impl Sealed for TopScreenLeft {} impl Sealed for TopScreenRight {} impl Sealed for BottomScreen {} - impl Sealed for Console<'_, S> {} + impl Sealed for Console<'_> {} } /// Trait to handle common functionality for all screens.