@@ -98,7 +98,6 @@ pub(crate) type WordList<S> = HashBag<Box<str>, FlagSet, S>;
98
98
/// [`new_with_hasher`]: struct.Dictionary.html#method.new_with_hasher
99
99
/// [`check`]: struct.Dictionary.html#method.check
100
100
/// [`add`]: struct.Dictionary.html#method.add
101
- // TODO: impl a dumb Debug for Dictionary.
102
101
// Allow passing down an Allocator too?
103
102
#[ derive( Clone ) ]
104
103
pub struct Dictionary < S = DefaultHashBuilder > {
@@ -186,7 +185,7 @@ impl<S: BuildHasher> Dictionary<S> {
186
185
/// Adds a word to the dictionary.
187
186
///
188
187
/// 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.
190
189
///
191
190
/// This function can be used to support for "personal" dictionaries. While clicking a
192
191
/// 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> {
231
230
}
232
231
}
233
232
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
+
234
241
/// Compressed representation of a Flag.
235
242
///
236
243
/// Flags are used as attributes about words. For example a flag might mark a word as forbidden,
@@ -635,7 +642,7 @@ mod test {
635
642
fn clone ( ) {
636
643
let aff = r#"
637
644
"# ;
638
- let dic = r#"1
645
+ let dic = r#"2
639
646
hello
640
647
world
641
648
"# ;
@@ -645,4 +652,16 @@ mod test {
645
652
assert ! ( dict. check( "foo" ) ) ;
646
653
assert ! ( !copy. check( "foo" ) ) ;
647
654
}
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
+ }
648
667
}
0 commit comments