]> git.nega.tv - josh/narcissus/commitdiff
narcissus-app: Fix clippy lint
authorJoshua Simmons <josh@nega.tv>
Sun, 5 Nov 2023 19:38:25 +0000 (20:38 +0100)
committerJoshua Simmons <josh@nega.tv>
Sun, 5 Nov 2023 19:58:51 +0000 (20:58 +0100)
engine/narcissus-app/src/lib.rs
engine/narcissus-app/src/sdl.rs

index 55239ef9b36985dffcad0afb6b94e3393b1677fb..bcf54d5050d8b195b40e8283af580743f0f39cf5 100644 (file)
@@ -2,7 +2,7 @@ mod button;
 mod key;
 mod sdl;
 
-use std::sync::Arc;
+use std::rc::Rc;
 
 use narcissus_core::{flags_def, raw_window::AsRawWindow, Upcast};
 
@@ -106,10 +106,10 @@ pub enum Event {
 }
 
 pub trait App {
-    fn create_window(&self, desc: &WindowDesc) -> Arc<dyn Window>;
-    fn destroy_window(&self, window: Arc<dyn Window>);
+    fn create_window(&self, desc: &WindowDesc) -> Rc<dyn Window>;
+    fn destroy_window(&self, window: Rc<dyn Window>);
 
-    fn window(&self, window_id: WindowId) -> Arc<dyn Window>;
+    fn window(&self, window_id: WindowId) -> Rc<dyn Window>;
 
     fn poll_event(&self) -> Option<Event>;
 }
index 7ce43f3a3713e7360d9af43b6f5ee084dec8c8fd..08febc7e64840d3a8472702b3c7c057e2dfd3d6b 100644 (file)
@@ -1,4 +1,4 @@
-use std::{collections::HashMap, ffi::CString, mem::MaybeUninit, sync::Arc};
+use std::{collections::HashMap, ffi::CString, mem::MaybeUninit, rc::Rc};
 
 use crate::{App, Button, Event, Key, ModifierFlags, PressedState, Window, WindowId};
 
@@ -65,7 +65,7 @@ impl Upcast<dyn AsRawWindow> for SdlWindow {
 }
 
 pub struct SdlApp {
-    windows: Mutex<HashMap<WindowId, Arc<SdlWindow>>>,
+    windows: Mutex<HashMap<WindowId, Rc<SdlWindow>>>,
 }
 
 impl SdlApp {
@@ -87,7 +87,7 @@ impl Drop for SdlApp {
 }
 
 impl App for SdlApp {
-    fn create_window(&self, desc: &crate::WindowDesc) -> Arc<dyn Window> {
+    fn create_window(&self, desc: &crate::WindowDesc) -> Rc<dyn Window> {
         let title = CString::new(desc.title).unwrap();
         let window = unsafe {
             sdl::SDL_CreateWindow(
@@ -101,16 +101,16 @@ impl App for SdlApp {
         };
         assert!(!window.is_null());
         let window_id = WindowId(unsafe { sdl::SDL_GetWindowID(window) } as u64);
-        let window = Arc::new(SdlWindow { window });
+        let window = Rc::new(SdlWindow { window });
         self.windows.lock().insert(window_id, window.clone());
         window
     }
 
-    fn destroy_window(&self, window: Arc<dyn Window>) {
+    fn destroy_window(&self, window: Rc<dyn Window>) {
         let window_id = window.id();
         drop(window);
         if let Some(mut window) = self.windows.lock().remove(&window_id) {
-            let window = Arc::get_mut(&mut window)
+            let window = Rc::get_mut(&mut window)
                 .expect("tried to destroy a window while there are outstanding references");
             unsafe { sdl::SDL_DestroyWindow(window.window) };
         }
@@ -200,7 +200,7 @@ impl App for SdlApp {
         Some(e)
     }
 
-    fn window(&self, window_id: WindowId) -> Arc<dyn Window> {
+    fn window(&self, window_id: WindowId) -> Rc<dyn Window> {
         self.windows.lock().get(&window_id).unwrap().clone()
     }
 }