Skip to content

Commit d1e4461

Browse files
committed
Add a dummy Display impl for Dictionary
1 parent bfeef51 commit d1e4461

File tree

1 file changed

+22
-3
lines changed

1 file changed

+22
-3
lines changed

src/lib.rs

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,6 @@ pub(crate) type WordList<S> = HashBag<Box<str>, FlagSet, S>;
9898
/// [`new_with_hasher`]: struct.Dictionary.html#method.new_with_hasher
9999
/// [`check`]: struct.Dictionary.html#method.check
100100
/// [`add`]: struct.Dictionary.html#method.add
101-
// TODO: impl a dumb Debug for Dictionary.
102101
// Allow passing down an Allocator too?
103102
#[derive(Clone)]
104103
pub struct Dictionary<S = DefaultHashBuilder> {
@@ -186,7 +185,7 @@ impl<S: BuildHasher> Dictionary<S> {
186185
/// Adds a word to the dictionary.
187186
///
188187
/// This function parses the input string the same way that Spellbook parses a line from a
189-
/// dictionary's `.dic` file. <!-- TODO: description of dic line parsing -->
188+
/// dictionary's `.dic` file. TODO: describe how a `.dic` line is parsed.
190189
///
191190
/// This function can be used to support for "personal" dictionaries. While clicking a
192191
/// misspelled word you might present a user with an option to add a misspelled word to the
@@ -231,6 +230,14 @@ impl<S: BuildHasher> Dictionary<S> {
231230
}
232231
}
233232

233+
impl core::fmt::Debug for Dictionary {
234+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
235+
f.debug_struct("Dictionary")
236+
.field("words", &self.words.len())
237+
.finish_non_exhaustive()
238+
}
239+
}
240+
234241
/// Compressed representation of a Flag.
235242
///
236243
/// Flags are used as attributes about words. For example a flag might mark a word as forbidden,
@@ -635,7 +642,7 @@ mod test {
635642
fn clone() {
636643
let aff = r#"
637644
"#;
638-
let dic = r#"1
645+
let dic = r#"2
639646
hello
640647
world
641648
"#;
@@ -645,4 +652,16 @@ mod test {
645652
assert!(dict.check("foo"));
646653
assert!(!copy.check("foo"));
647654
}
655+
656+
#[test]
657+
fn debug() {
658+
let aff = r#"
659+
"#;
660+
let dic = r#"2
661+
hello
662+
world
663+
"#;
664+
let dict = Dictionary::new(aff, dic).unwrap();
665+
assert_eq!(&alloc::format!("{dict:?}"), "Dictionary { words: 2, .. }");
666+
}
648667
}

0 commit comments

Comments
 (0)