Skip to content
This repository was archived by the owner on Jun 8, 2021. It is now read-only.

Commit e003445

Browse files
authored
Merge pull request #577 from sdroege/more-debug
Derive fmt::Debug for a few more types
2 parents 78d6fb9 + 899f874 commit e003445

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

src/object.rs

+4
Original file line numberDiff line numberDiff line change
@@ -1158,6 +1158,7 @@ macro_rules! glib_object_wrapper {
11581158

11591159
(@class_impl $name:ident, $ffi_class_name:path, $rust_class_name:ident) => {
11601160
#[repr(C)]
1161+
#[derive(Debug)]
11611162
pub struct $rust_class_name($ffi_class_name);
11621163

11631164
unsafe impl $crate::object::IsClassFor for $rust_class_name {
@@ -1916,6 +1917,7 @@ glib_wrapper! {
19161917
}
19171918
}
19181919

1920+
#[derive(Debug)]
19191921
pub struct WeakRef<T: ObjectType>(Box<gobject_sys::GWeakRef>, PhantomData<*const T>);
19201922

19211923
impl<T: ObjectType> WeakRef<T> {
@@ -1979,6 +1981,7 @@ unsafe impl<T: ObjectType + Send + Sync> Send for WeakRef<T> {}
19791981
/// Trying to upgrade the weak reference from another thread than the one
19801982
/// where it was created on will panic but dropping or cloning can be done
19811983
/// safely from any thread.
1984+
#[derive(Debug)]
19821985
pub struct SendWeakRef<T: ObjectType>(WeakRef<T>, Option<usize>);
19831986

19841987
impl<T: ObjectType> SendWeakRef<T> {
@@ -2029,6 +2032,7 @@ impl<T: ObjectType> From<WeakRef<T>> for SendWeakRef<T> {
20292032
unsafe impl<T: ObjectType> Sync for SendWeakRef<T> {}
20302033
unsafe impl<T: ObjectType> Send for SendWeakRef<T> {}
20312034

2035+
#[derive(Debug)]
20322036
pub struct BindingBuilder<'a> {
20332037
source: &'a ObjectRef,
20342038
source_property: &'a str,

src/subclass/simple.rs

+23
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use super::prelude::*;
1010
use object::ObjectType;
1111

12+
use std::fmt;
1213
use std::ops;
1314

1415
/// A simple instance struct that does not store any additional data.
@@ -17,6 +18,17 @@ pub struct InstanceStruct<T: ObjectSubclass> {
1718
parent: <T::ParentType as ObjectType>::GlibType,
1819
}
1920

21+
impl<T: ObjectSubclass> fmt::Debug for InstanceStruct<T>
22+
where
23+
<T::ParentType as ObjectType>::GlibType: fmt::Debug,
24+
{
25+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
26+
f.debug_struct("InstanceStruct")
27+
.field("parent", &self.parent)
28+
.finish()
29+
}
30+
}
31+
2032
unsafe impl<T: ObjectSubclass> super::types::InstanceStruct for InstanceStruct<T> {
2133
type Type = T;
2234
}
@@ -28,6 +40,17 @@ pub struct ClassStruct<T: ObjectSubclass> {
2840
parent_class: <T::ParentType as ObjectType>::GlibClassType,
2941
}
3042

43+
impl<T: ObjectSubclass> fmt::Debug for ClassStruct<T>
44+
where
45+
<T::ParentType as ObjectType>::GlibClassType: fmt::Debug,
46+
{
47+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
48+
f.debug_struct("InstanceStruct")
49+
.field("parent_class", &self.parent_class)
50+
.finish()
51+
}
52+
}
53+
3154
unsafe impl<T: ObjectSubclass> super::types::ClassStruct for ClassStruct<T> {
3255
type Type = T;
3356
}

0 commit comments

Comments
 (0)