Skip to content

Commit f72dee7

Browse files
committed
String, StringName, NodePath: Debug uses GDScript literals "str", &"name", ^"path"
1 parent 6d18f49 commit f72dee7

File tree

3 files changed

+24
-17
lines changed

3 files changed

+24
-17
lines changed

godot-core/src/builtin/node_path.rs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@
44
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
55
*/
66

7+
use std::fmt;
8+
79
use crate::builtin::GodotString;
810
use godot_ffi as sys;
911
use godot_ffi::{ffi_methods, GDExtensionTypePtr, GodotFfi};
10-
use std::fmt::{Display, Formatter, Result as FmtResult};
1112

1213
pub struct NodePath {
1314
opaque: sys::types::OpaqueNodePath,
@@ -59,10 +60,18 @@ impl From<&str> for NodePath {
5960
}
6061
}
6162

62-
impl Display for NodePath {
63-
fn fmt(&self, f: &mut Formatter<'_>) -> FmtResult {
63+
impl fmt::Display for NodePath {
64+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
65+
let string = GodotString::from(self);
66+
<GodotString as fmt::Display>::fmt(&string, f)
67+
}
68+
}
69+
70+
/// Uses literal syntax from GDScript: `^"node_path"`
71+
impl fmt::Debug for NodePath {
72+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
6473
let string = GodotString::from(self);
65-
<GodotString as Display>::fmt(&string, f)
74+
write!(f, "^\"{string}\"")
6675
}
6776
}
6877

godot-core/src/builtin/string.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,10 +110,11 @@ impl fmt::Display for GodotString {
110110
}
111111
}
112112

113+
/// Uses literal syntax from GDScript: `"string"`
113114
impl fmt::Debug for GodotString {
114115
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
115116
let s = String::from(self);
116-
write!(f, "GodotString(\"{s}\")")
117+
write!(f, "\"{s}\"")
117118
}
118119
}
119120

godot-core/src/builtin/string_name.rs

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use crate::builtin::GodotString;
88
use godot_ffi as sys;
99
use sys::{ffi_methods, GodotFfi};
1010

11-
use std::fmt::{Debug, Display, Formatter, Result as FmtResult};
11+
use std::fmt;
1212
use std::hash::{Hash, Hasher};
1313

1414
#[repr(C)]
@@ -68,21 +68,18 @@ impl Default for StringName {
6868
}
6969
}
7070

71-
impl Display for StringName {
72-
fn fmt(&self, f: &mut Formatter<'_>) -> FmtResult {
73-
// TODO consider using GDScript built-in to_string()
74-
71+
impl fmt::Display for StringName {
72+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
7573
let s = GodotString::from(self);
76-
<GodotString as Display>::fmt(&s, f)
74+
<GodotString as fmt::Display>::fmt(&s, f)
7775
}
7876
}
7977

80-
impl Debug for StringName {
81-
fn fmt(&self, f: &mut Formatter<'_>) -> FmtResult {
82-
// TODO consider using GDScript built-in to_string()
83-
84-
let s = GodotString::from(self);
85-
<GodotString as Debug>::fmt(&s, f)
78+
/// Uses literal syntax from GDScript: `&"string_name"`
79+
impl fmt::Debug for StringName {
80+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
81+
let string = GodotString::from(self);
82+
write!(f, "&\"{string}\"")
8683
}
8784
}
8885

0 commit comments

Comments
 (0)