Skip to content

Commit 32fb7f3

Browse files
authored
Merge pull request #879 from joriskleiber/feature/onready-debug
Implement Debug for InitState and OnReady
2 parents 68bcda7 + 1ff53c3 commit 32fb7f3

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

godot-core/src/obj/onready.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use crate::classes::Node;
1010
use crate::meta::GodotConvert;
1111
use crate::obj::{Gd, GodotClass, Inherits};
1212
use crate::registry::property::Var;
13+
use std::fmt::{self, Debug, Formatter};
1314
use std::mem;
1415

1516
/// Ergonomic late-initialization container with `ready()` support.
@@ -103,6 +104,7 @@ use std::mem;
103104
/// }
104105
/// }
105106
/// ```
107+
#[derive(Debug)]
106108
pub struct OnReady<T> {
107109
state: InitState<T>,
108110
}
@@ -280,3 +282,19 @@ enum InitState<T> {
280282
AutoInitializing, // needed because state cannot be empty
281283
Initialized { value: T },
282284
}
285+
286+
impl<T: Debug> Debug for InitState<T> {
287+
fn fmt(&self, fmt: &mut Formatter<'_>) -> fmt::Result {
288+
match self {
289+
InitState::ManualUninitialized => fmt.debug_struct("ManualUninitialized").finish(),
290+
InitState::AutoPrepared { .. } => {
291+
fmt.debug_struct("AutoPrepared").finish_non_exhaustive()
292+
}
293+
InitState::AutoInitializing => fmt.debug_struct("AutoInitializing").finish(),
294+
InitState::Initialized { value } => fmt
295+
.debug_struct("Initialized")
296+
.field("value", value)
297+
.finish(),
298+
}
299+
}
300+
}

0 commit comments

Comments
 (0)