[librsvg/bilelmoussaoui/param-spec: 4/4] c-api: Use derive Default for ObjectSubclass state




commit 5c20f4905aa871e7abbf0199eb3434ce007dc763
Author: Bilal Elmoussaoui <belmouss redhat com>
Date:   Sat Jul 23 09:28:12 2022 +0200

    c-api: Use derive Default for ObjectSubclass state
    
    By default the attribute macro object_subclass
    uses T::default inside the new method implementation
    
    Part-of: <https://gitlab.gnome.org/GNOME/librsvg/-/merge_requests/721>

 src/c_api/handle.rs | 21 ++++++++-------------
 1 file changed, 8 insertions(+), 13 deletions(-)
---
diff --git a/src/c_api/handle.rs b/src/c_api/handle.rs
index 3f2fafad2..549bcede1 100644
--- a/src/c_api/handle.rs
+++ b/src/c_api/handle.rs
@@ -208,6 +208,12 @@ impl LoadState {
     }
 }
 
+impl Default for LoadState {
+    fn default() -> Self {
+        Self::Start
+    }
+}
+
 /// Holds the base URL for loading a handle, and the C-accessible version of it
 ///
 /// There is a public API to query the base URL, and we need to
@@ -287,11 +293,13 @@ mod imp {
 
     /// Contains all the interior mutability for a RsvgHandle to be called
     /// from the C API.
+    #[derive(Default)]
     pub struct CHandle {
         pub(super) inner: RefCell<CHandleInner>,
         pub(super) load_state: RefCell<LoadState>,
     }
 
+    #[derive(Default)]
     pub(super) struct CHandleInner {
         pub(super) dpi: Dpi,
         pub(super) load_flags: LoadFlags,
@@ -308,19 +316,6 @@ mod imp {
 
         type Instance = RsvgHandle;
         type Class = RsvgHandleClass;
-
-        fn new() -> Self {
-            CHandle {
-                inner: RefCell::new(CHandleInner {
-                    dpi: Dpi::default(),
-                    load_flags: LoadFlags::default(),
-                    base_url: BaseUrl::default(),
-                    size_callback: SizeCallback::default(),
-                    is_testing: false,
-                }),
-                load_state: RefCell::new(LoadState::Start),
-            }
-        }
     }
 
     impl ObjectImpl for CHandle {


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]