Skip to content

Commit 78bae46

Browse files
committed
Fixes for debug formatting
* Debug now prints full values for the internal representation, which is more helpful when combined with a hex or binary printing mode. * Display now properly renders all the scripts with " + " seperators.
1 parent 1f84c2e commit 78bae46

File tree

1 file changed

+10
-20
lines changed

1 file changed

+10
-20
lines changed

src/lib.rs

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ impl fmt::Display for Script {
131131
}
132132
}
133133

134-
#[derive(Clone, Copy, PartialEq, Eq, Hash)]
134+
#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)]
135135
#[non_exhaustive]
136136
/// A value for the `Script_Extension` property
137137
///
@@ -311,33 +311,23 @@ impl From<&'_ str> for ScriptExtension {
311311
}
312312
}
313313

314-
impl fmt::Debug for ScriptExtension {
315-
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
316-
write!(f, "ScriptExtension(")?;
317-
fmt::Display::fmt(self, f)?;
318-
write!(f, ")")
319-
}
320-
}
321-
322314
impl fmt::Display for ScriptExtension {
323315
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
324-
if self.is_common() {
325-
write!(f, "Common")?;
326-
} else if self.is_inherited() {
327-
write!(f, "Inherited")?;
328-
} else if self.is_empty() {
316+
write!(f, "ScriptExtension(")?;
317+
if self.is_empty() {
329318
write!(f, "Unknown")?;
330319
} else {
331320
let mut first = true;
332321
for script in self.iter() {
333-
if !first {
334-
write!(f, " + ")?;
322+
if first {
335323
first = false;
324+
} else {
325+
write!(f, " + ")?;
336326
}
337327
script.full_name().fmt(f)?;
338328
}
339329
}
340-
Ok(())
330+
write!(f, ")")
341331
}
342332
}
343333

@@ -361,7 +351,7 @@ impl UnicodeScript for char {
361351

362352
/// Iterator over scripts in a [ScriptExtension].
363353
///
364-
/// Can be obtained ia [ScriptExtension::iter()]
354+
/// Can be obtained via [ScriptExtension::iter()]
365355
pub struct ScriptIterator {
366356
ext: ScriptExtension,
367357
}
@@ -445,11 +435,11 @@ mod tests {
445435
let ext = ScriptExtension::for_str(s);
446436
assert_eq!(ext, script_extensions::DEVA);
447437
println!(
448-
"{:?}",
438+
"{}",
449439
script_extensions::DEVA_DOGR_GUJR_GURU_KHOJ_KTHI_MAHJ_MODI_SIND_TAKR_TIRH
450440
);
451441
println!(
452-
"{:?}",
442+
"{}",
453443
ext.intersection(
454444
script_extensions::DEVA_DOGR_GUJR_GURU_KHOJ_KTHI_MAHJ_MODI_SIND_TAKR_TIRH
455445
)

0 commit comments

Comments
 (0)