Skip to content

Commit ec9b8ff

Browse files
committed
Implement Debug for all types
1 parent e2d94d0 commit ec9b8ff

File tree

13 files changed

+82
-2
lines changed

13 files changed

+82
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
- Update to `objc2` 0.6.0.
44
- Bump MSRV to Rust 1.71.
55
- Make `Context` clonable.
6+
- `Context`, `Surface` and `Buffer` now implement `Debug`.
67

78
# 0.4.6
89

src/backend_dispatch.rs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
use crate::{backend_interface::*, backends, InitError, Rect, SoftBufferError};
44

55
use raw_window_handle::{HasDisplayHandle, HasWindowHandle};
6+
use std::fmt;
67
use std::num::NonZeroU32;
78
#[cfg(any(wayland_platform, x11_platform, kms_platform))]
89
use std::sync::Arc;
@@ -56,6 +57,17 @@ macro_rules! make_dispatch {
5657
}
5758
}
5859

60+
impl<D: fmt::Debug> fmt::Debug for ContextDispatch<D> {
61+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
62+
match self {
63+
$(
64+
$(#[$attr])*
65+
Self::$name(inner) => inner.fmt(f),
66+
)*
67+
}
68+
}
69+
}
70+
5971
#[allow(clippy::large_enum_variant)] // it's boxed anyways
6072
pub(crate) enum SurfaceDispatch<$dgen, $wgen> {
6173
$(
@@ -117,6 +129,17 @@ macro_rules! make_dispatch {
117129
}
118130
}
119131

132+
impl<D: fmt::Debug, W: fmt::Debug> fmt::Debug for SurfaceDispatch<D, W> {
133+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
134+
match self {
135+
$(
136+
$(#[$attr])*
137+
Self::$name(inner) => inner.fmt(f),
138+
)*
139+
}
140+
}
141+
}
142+
120143
pub(crate) enum BufferDispatch<'a, $dgen, $wgen> {
121144
$(
122145
$(#[$attr])*
@@ -172,6 +195,17 @@ macro_rules! make_dispatch {
172195
}
173196
}
174197
}
198+
199+
impl<D: fmt::Debug, W: fmt::Debug> fmt::Debug for BufferDispatch<'_, D, W> {
200+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
201+
match self {
202+
$(
203+
$(#[$attr])*
204+
Self::$name(inner) => inner.fmt(f),
205+
)*
206+
}
207+
}
208+
}
175209
};
176210
}
177211

src/backends/android.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ use crate::error::InitError;
1515
use crate::{BufferInterface, Rect, SoftBufferError, SurfaceInterface};
1616

1717
/// The handle to a window for software buffering.
18+
#[derive(Debug)]
1819
pub struct AndroidImpl<D, W> {
1920
native_window: NativeWindow,
2021
window: W,
@@ -113,6 +114,7 @@ impl<D: HasDisplayHandle, W: HasWindowHandle> SurfaceInterface<D, W> for Android
113114
}
114115
}
115116

117+
#[derive(Debug)]
116118
pub struct BufferImpl<'a, D: ?Sized, W> {
117119
native_window_buffer: NativeWindowBufferLockGuard<'a>,
118120
buffer: Vec<u32>,

src/backends/cg.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ define_class!(
2828
#[unsafe(super(NSObject))]
2929
#[name = "SoftbufferObserver"]
3030
#[ivars = SendCALayer]
31+
#[derive(Debug)]
3132
struct Observer;
3233

3334
/// NSKeyValueObserving
@@ -92,6 +93,7 @@ impl Observer {
9293
}
9394
}
9495

96+
#[derive(Debug)]
9597
pub struct CGImpl<D, W> {
9698
/// Our layer.
9799
layer: SendCALayer,
@@ -263,6 +265,7 @@ impl<D: HasDisplayHandle, W: HasWindowHandle> SurfaceInterface<D, W> for CGImpl<
263265
}
264266
}
265267

268+
#[derive(Debug)]
266269
pub struct BufferImpl<'a, D, W> {
267270
imp: &'a mut CGImpl<D, W>,
268271
buffer: Box<[u32]>,
@@ -344,6 +347,7 @@ impl<D: HasDisplayHandle, W: HasWindowHandle> BufferInterface for BufferImpl<'_,
344347
}
345348
}
346349

350+
#[derive(Debug)]
347351
struct SendCALayer(Retained<CALayer>);
348352

349353
// SAFETY: CALayer is dubiously thread safe, like most things in Core Animation.

src/backends/kms.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ use drm::Device;
1212
use raw_window_handle::{HasDisplayHandle, HasWindowHandle, RawDisplayHandle, RawWindowHandle};
1313

1414
use std::collections::HashSet;
15+
use std::fmt;
1516
use std::marker::PhantomData;
1617
use std::num::NonZeroU32;
1718
use std::os::unix::io::{AsFd, BorrowedFd};
@@ -118,6 +119,13 @@ pub(crate) struct BufferImpl<'a, D: ?Sized, W: ?Sized> {
118119
_window: PhantomData<&'a mut W>,
119120
}
120121

122+
impl<D: ?Sized + fmt::Debug, W: ?Sized + fmt::Debug> fmt::Debug for BufferImpl<'_, D, W> {
123+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
124+
// FIXME: Derive instead once `DumbMapping` impls `Debug`.
125+
f.debug_struct("BufferImpl").finish_non_exhaustive()
126+
}
127+
}
128+
121129
/// The combined frame buffer and dumb buffer.
122130
#[derive(Debug)]
123131
struct SharedBuffer {

src/backends/orbital.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use std::{cmp, marker::PhantomData, num::NonZeroU32, slice, str};
55
use crate::backend_interface::*;
66
use crate::{Rect, SoftBufferError};
77

8+
#[derive(Debug)]
89
struct OrbitalMap {
910
address: usize,
1011
size: usize,
@@ -55,6 +56,7 @@ impl Drop for OrbitalMap {
5556
}
5657
}
5758

59+
#[derive(Debug)]
5860
pub struct OrbitalImpl<D, W> {
5961
handle: ThreadSafeWindowHandle,
6062
width: u32,
@@ -64,6 +66,7 @@ pub struct OrbitalImpl<D, W> {
6466
_display: PhantomData<D>,
6567
}
6668

69+
#[derive(Debug)]
6770
struct ThreadSafeWindowHandle(OrbitalWindowHandle);
6871
unsafe impl Send for ThreadSafeWindowHandle {}
6972
unsafe impl Sync for ThreadSafeWindowHandle {}
@@ -180,11 +183,13 @@ impl<D: HasDisplayHandle, W: HasWindowHandle> SurfaceInterface<D, W> for Orbital
180183
}
181184
}
182185

186+
#[derive(Debug)]
183187
enum Pixels {
184188
Mapping(OrbitalMap),
185189
Buffer(Vec<u32>),
186190
}
187191

192+
#[derive(Debug)]
188193
pub struct BufferImpl<'a, D, W> {
189194
imp: &'a mut OrbitalImpl<D, W>,
190195
pixels: Pixels,

src/backends/wayland/buffer.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ unsafe fn map_file(file: &File) -> MmapMut {
6767
unsafe { MmapMut::map_mut(file.as_raw_fd()).expect("Failed to map shared memory") }
6868
}
6969

70+
#[derive(Debug)]
7071
pub(super) struct WaylandBuffer {
7172
qh: QueueHandle<State>,
7273
tempfile: File,

src/backends/wayland/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ use buffer::WaylandBuffer;
2020

2121
struct State;
2222

23+
#[derive(Debug)]
2324
pub struct WaylandDisplayImpl<D: ?Sized> {
2425
conn: Option<Connection>,
2526
event_queue: Mutex<EventQueue<State>>,
@@ -74,6 +75,7 @@ impl<D: ?Sized> Drop for WaylandDisplayImpl<D> {
7475
}
7576
}
7677

78+
#[derive(Debug)]
7779
pub struct WaylandImpl<D: ?Sized, W: ?Sized> {
7880
display: Arc<WaylandDisplayImpl<D>>,
7981
surface: Option<wl_surface::WlSurface>,
@@ -257,6 +259,7 @@ impl<D: ?Sized, W: ?Sized> Drop for WaylandImpl<D, W> {
257259
}
258260
}
259261

262+
#[derive(Debug)]
260263
pub struct BufferImpl<'a, D: ?Sized, W> {
261264
stack: util::BorrowStack<'a, WaylandImpl<D, W>, [u32]>,
262265
age: u8,

src/backends/web.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use std::num::NonZeroU32;
1818
/// Display implementation for the web platform.
1919
///
2020
/// This just caches the document to prevent having to query it every time.
21-
#[derive(Clone)]
21+
#[derive(Clone, Debug)]
2222
pub struct WebDisplayImpl<D> {
2323
document: web_sys::Document,
2424
_display: D,
@@ -43,6 +43,7 @@ impl<D: HasDisplayHandle> ContextInterface<D> for WebDisplayImpl<D> {
4343
}
4444
}
4545

46+
#[derive(Debug)]
4647
pub struct WebImpl<D, W> {
4748
/// The handle and context to the canvas that we're drawing to.
4849
canvas: Canvas,
@@ -65,6 +66,7 @@ pub struct WebImpl<D, W> {
6566

6667
/// Holding canvas and context for [`HtmlCanvasElement`] or [`OffscreenCanvas`],
6768
/// since they have different types.
69+
#[derive(Debug)]
6870
enum Canvas {
6971
Canvas {
7072
canvas: HtmlCanvasElement,
@@ -373,6 +375,7 @@ impl Canvas {
373375
}
374376
}
375377

378+
#[derive(Debug)]
376379
pub struct BufferImpl<'a, D, W> {
377380
imp: &'a mut WebImpl<D, W>,
378381
}

src/backends/win32.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ const ZERO_QUAD: Gdi::RGBQUAD = Gdi::RGBQUAD {
2525
rgbReserved: 0,
2626
};
2727

28+
#[derive(Debug)]
2829
struct Buffer {
2930
dc: Gdi::HDC,
3031
bitmap: Gdi::HBITMAP,
@@ -135,6 +136,7 @@ impl Buffer {
135136
}
136137

137138
/// The handle to a window for software buffering.
139+
#[derive(Debug)]
138140
pub struct Win32Impl<D: ?Sized, W> {
139141
/// The window handle.
140142
window: OnlyUsedFromOrigin<HWND>,
@@ -281,6 +283,7 @@ impl<D: HasDisplayHandle, W: HasWindowHandle> SurfaceInterface<D, W> for Win32Im
281283
}
282284
}
283285

286+
#[derive(Debug)]
284287
pub struct BufferImpl<'a, D, W>(&'a mut Win32Impl<D, W>);
285288

286289
impl<D: HasDisplayHandle, W: HasWindowHandle> BufferInterface for BufferImpl<'_, D, W> {
@@ -460,6 +463,7 @@ impl Command {
460463
}
461464
}
462465

466+
#[derive(Debug)]
463467
struct OnlyUsedFromOrigin<T>(T);
464468
unsafe impl<T> Send for OnlyUsedFromOrigin<T> {}
465469

0 commit comments

Comments
 (0)