@@ -191,225 +191,141 @@ impl From<BuiltInLanguage> for AnyLanguage {
191191 }
192192}
193193
194- /// The `English` language.
195- ///
196- /// The `English` language is always available; other languages are enabled via
197- /// compilation features.
198- #[ derive( Copy , Clone , Debug , Ord , PartialOrd , Eq , PartialEq , Hash ) ]
199- pub struct English ;
200-
201- impl WordlistProvider for English {
202- #[ inline]
203- fn wordlist ( ) -> & ' static Wordlist {
204- & wordlists:: english:: WORDLIST
205- }
206- }
207-
208- impl English {
209- /// Returns the full BIP-0039 English word list (2048 words) in BIP-0039 order.
210- #[ inline]
211- pub fn words ( ) -> & ' static [ & ' static str ; 2048 ] {
212- & wordlists:: english:: WORDS
213- }
214- }
215-
216- /// The `Simplified Chinese` language.
217- #[ cfg( feature = "chinese-simplified" ) ]
218- #[ derive( Copy , Clone , Debug , Ord , PartialOrd , Eq , PartialEq , Hash ) ]
219- pub struct ChineseSimplified ;
220-
221- #[ cfg( feature = "chinese-simplified" ) ]
222- impl WordlistProvider for ChineseSimplified {
223- #[ inline]
224- fn wordlist ( ) -> & ' static Wordlist {
225- & wordlists:: chinese_simplified:: WORDLIST
226- }
227- }
228-
229- #[ cfg( feature = "chinese-simplified" ) ]
230- impl ChineseSimplified {
231- /// Returns the full BIP-0039 Simplified Chinese word list (2048 words) in BIP-0039 order.
232- #[ inline]
233- pub fn words ( ) -> & ' static [ & ' static str ; 2048 ] {
234- & wordlists:: chinese_simplified:: WORDS
235- }
236- }
237-
238- /// The `Traditional Chinese` language.
239- #[ cfg( feature = "chinese-traditional" ) ]
240- #[ derive( Copy , Clone , Debug , Ord , PartialOrd , Eq , PartialEq , Hash ) ]
241- pub struct ChineseTraditional ;
242-
243- #[ cfg( feature = "chinese-traditional" ) ]
244- impl WordlistProvider for ChineseTraditional {
245- #[ inline]
246- fn wordlist ( ) -> & ' static Wordlist {
247- & wordlists:: chinese_traditional:: WORDLIST
248- }
249- }
250-
251- #[ cfg( feature = "chinese-traditional" ) ]
252- impl ChineseTraditional {
253- /// Returns the full BIP-0039 Traditional Chinese word list (2048 words) in BIP-0039 order.
254- #[ inline]
255- pub fn words ( ) -> & ' static [ & ' static str ; 2048 ] {
256- & wordlists:: chinese_traditional:: WORDS
257- }
258- }
259-
260- /// The `Czech` language.
261- #[ cfg( feature = "czech" ) ]
262- #[ derive( Copy , Clone , Debug , Ord , PartialOrd , Eq , PartialEq , Hash ) ]
263- pub struct Czech ;
264-
265- #[ cfg( feature = "czech" ) ]
266- impl WordlistProvider for Czech {
267- #[ inline]
268- fn wordlist ( ) -> & ' static Wordlist {
269- & wordlists:: czech:: WORDLIST
270- }
271- }
272-
273- #[ cfg( feature = "czech" ) ]
274- impl Czech {
275- /// Returns the full BIP-0039 Czech word list (2048 words) in BIP-0039 order.
276- #[ inline]
277- pub fn words ( ) -> & ' static [ & ' static str ; 2048 ] {
278- & wordlists:: czech:: WORDS
279- }
280- }
281-
282- /// The `French` language.
283- #[ cfg( feature = "french" ) ]
284- #[ derive( Copy , Clone , Debug , Ord , PartialOrd , Eq , PartialEq , Hash ) ]
285- pub struct French ;
286-
287- #[ cfg( feature = "french" ) ]
288- impl WordlistProvider for French {
289- #[ inline]
290- fn wordlist ( ) -> & ' static Wordlist {
291- & wordlists:: french:: WORDLIST
292- }
293- }
294-
295- #[ cfg( feature = "french" ) ]
296- impl French {
297- /// Returns the full BIP-0039 French word list (2048 words) in BIP-0039 order.
298- #[ inline]
299- pub fn words ( ) -> & ' static [ & ' static str ; 2048 ] {
300- & wordlists:: french:: WORDS
301- }
302- }
303-
304- /// The `Italian` language.
305- #[ cfg( feature = "italian" ) ]
306- #[ derive( Copy , Clone , Debug , Ord , PartialOrd , Eq , PartialEq , Hash ) ]
307- pub struct Italian ;
308-
309- #[ cfg( feature = "italian" ) ]
310- impl WordlistProvider for Italian {
311- #[ inline]
312- fn wordlist ( ) -> & ' static Wordlist {
313- & wordlists:: italian:: WORDLIST
314- }
315- }
316-
317- #[ cfg( feature = "italian" ) ]
318- impl Italian {
319- /// Returns the full BIP-0039 Italian word list (2048 words) in BIP-0039 order.
320- #[ inline]
321- pub fn words ( ) -> & ' static [ & ' static str ; 2048 ] {
322- & wordlists:: italian:: WORDS
323- }
324- }
325-
326- /// The `Japanese` language.
327- #[ cfg( feature = "japanese" ) ]
328- #[ derive( Copy , Clone , Debug , Ord , PartialOrd , Eq , PartialEq , Hash ) ]
329- pub struct Japanese ;
330-
331- #[ cfg( feature = "japanese" ) ]
332- impl WordlistProvider for Japanese {
333- #[ inline]
334- fn wordlist ( ) -> & ' static Wordlist {
335- & wordlists:: japanese:: WORDLIST
336- }
337- }
338-
339- #[ cfg( feature = "japanese" ) ]
340- impl Japanese {
341- /// Returns the full BIP-0039 Japanese word list (2048 words) in BIP-0039 order.
342- #[ inline]
343- pub fn words ( ) -> & ' static [ & ' static str ; 2048 ] {
344- & wordlists:: japanese:: WORDS
345- }
346- }
347-
348- /// The `Korean` language.
349- #[ cfg( feature = "korean" ) ]
350- #[ derive( Copy , Clone , Debug , Ord , PartialOrd , Eq , PartialEq , Hash ) ]
351- pub struct Korean ;
352-
353- #[ cfg( feature = "korean" ) ]
354- impl WordlistProvider for Korean {
355- #[ inline]
356- fn wordlist ( ) -> & ' static Wordlist {
357- & wordlists:: korean:: WORDLIST
358- }
359- }
360-
361- #[ cfg( feature = "korean" ) ]
362- impl Korean {
363- /// Returns the full BIP-0039 Korean word list (2048 words) in BIP-0039 order.
364- #[ inline]
365- pub fn words ( ) -> & ' static [ & ' static str ; 2048 ] {
366- & wordlists:: korean:: WORDS
367- }
368- }
369-
370- /// The `Portuguese` language.
371- #[ cfg( feature = "portuguese" ) ]
372- #[ derive( Copy , Clone , Debug , Ord , PartialOrd , Eq , PartialEq , Hash ) ]
373- pub struct Portuguese ;
374-
375- #[ cfg( feature = "portuguese" ) ]
376- impl WordlistProvider for Portuguese {
377- #[ inline]
378- fn wordlist ( ) -> & ' static Wordlist {
379- & wordlists:: portuguese:: WORDLIST
380- }
381- }
382-
383- #[ cfg( feature = "portuguese" ) ]
384- impl Portuguese {
385- /// Returns the full BIP-0039 Portuguese word list (2048 words) in BIP-0039 order.
386- #[ inline]
387- pub fn words ( ) -> & ' static [ & ' static str ; 2048 ] {
388- & wordlists:: portuguese:: WORDS
389- }
390- }
194+ macro_rules! define_builtin_language {
195+ (
196+ $( doc = $doc: literal, ) +
197+ name = $name: ident,
198+ wordlist = $wordlist: ident $( , ) ?
199+ ) => {
200+ $( #[ doc = $doc] ) *
201+ #[ derive( Copy , Clone , Debug , Ord , PartialOrd , Eq , PartialEq , Hash ) ]
202+ pub struct $name;
203+
204+ impl WordlistProvider for $name {
205+ #[ inline]
206+ fn wordlist( ) -> & ' static Wordlist {
207+ & wordlists:: $wordlist:: WORDLIST
208+ }
209+ }
391210
392- /// The `Spanish` language.
393- #[ cfg( feature = "spanish" ) ]
394- #[ derive( Copy , Clone , Debug , Ord , PartialOrd , Eq , PartialEq , Hash ) ]
395- pub struct Spanish ;
211+ impl $name {
212+ #[ doc = concat!(
213+ "Returns the full BIP-0039 `" ,
214+ stringify!( $name) ,
215+ "` word list (2048 words) in BIP-0039 order."
216+ ) ]
217+ #[ inline]
218+ pub fn words( ) -> & ' static [ & ' static str ; 2048 ] {
219+ & wordlists:: $wordlist:: WORDS
220+ }
221+ }
222+ } ;
223+ (
224+ $( doc = $doc: literal, ) +
225+ name = $name: ident,
226+ wordlist = $wordlist: ident,
227+ feature = $feature: literal,
228+ $( , ) ?
229+ ) => {
230+ $( #[ doc = $doc] ) *
231+ #[ cfg( feature = $feature) ]
232+ #[ derive( Copy , Clone , Debug , Ord , PartialOrd , Eq , PartialEq , Hash ) ]
233+ pub struct $name;
234+
235+ #[ cfg( feature = $feature) ]
236+ impl WordlistProvider for $name {
237+ #[ inline]
238+ fn wordlist( ) -> & ' static Wordlist {
239+ & wordlists:: $wordlist:: WORDLIST
240+ }
241+ }
396242
397- #[ cfg( feature = "spanish" ) ]
398- impl WordlistProvider for Spanish {
399- #[ inline]
400- fn wordlist ( ) -> & ' static Wordlist {
401- & wordlists:: spanish:: WORDLIST
402- }
243+ #[ cfg( feature = $feature) ]
244+ impl $name {
245+ #[ doc = concat!(
246+ "Returns the full BIP-0039 `" ,
247+ stringify!( $name) ,
248+ "` word list (2048 words) in BIP-0039 order."
249+ ) ]
250+ #[ inline]
251+ pub fn words( ) -> & ' static [ & ' static str ; 2048 ] {
252+ & wordlists:: $wordlist:: WORDS
253+ }
254+ }
255+ } ;
403256}
404257
405- #[ cfg( feature = "spanish" ) ]
406- impl Spanish {
407- /// Returns the full BIP-0039 Spanish word list (2048 words) in BIP-0039 order.
408- #[ inline]
409- pub fn words ( ) -> & ' static [ & ' static str ; 2048 ] {
410- & wordlists:: spanish:: WORDS
411- }
412- }
258+ define_builtin_language ! (
259+ doc = r#"The `English` language.
260+
261+ The `English` language is always available; other languages are enabled via
262+ compilation features."# ,
263+ name = English ,
264+ wordlist = english,
265+ ) ;
266+
267+ define_builtin_language ! (
268+ doc = "The `Simplified Chinese` language." ,
269+ name = ChineseSimplified ,
270+ wordlist = chinese_simplified,
271+ feature = "chinese-simplified" ,
272+ ) ;
273+
274+ define_builtin_language ! (
275+ doc = "The `Traditional Chinese` language." ,
276+ name = ChineseTraditional ,
277+ wordlist = chinese_traditional,
278+ feature = "chinese-traditional" ,
279+ ) ;
280+
281+ define_builtin_language ! (
282+ doc = "The `Czech` language." ,
283+ name = Czech ,
284+ wordlist = czech,
285+ feature = "czech" ,
286+ ) ;
287+
288+ define_builtin_language ! (
289+ doc = "The `French` language." ,
290+ name = French ,
291+ wordlist = french,
292+ feature = "french" ,
293+ ) ;
294+
295+ define_builtin_language ! (
296+ doc = "The `Italian` language." ,
297+ name = Italian ,
298+ wordlist = italian,
299+ feature = "italian" ,
300+ ) ;
301+
302+ define_builtin_language ! (
303+ doc = "The `Japanese` language." ,
304+ name = Japanese ,
305+ wordlist = japanese,
306+ feature = "japanese" ,
307+ ) ;
308+
309+ define_builtin_language ! (
310+ doc = "The `Korean` language." ,
311+ name = Korean ,
312+ wordlist = korean,
313+ feature = "korean" ,
314+ ) ;
315+
316+ define_builtin_language ! (
317+ doc = "The `Portuguese` language." ,
318+ name = Portuguese ,
319+ wordlist = portuguese,
320+ feature = "portuguese" ,
321+ ) ;
322+
323+ define_builtin_language ! (
324+ doc = "The `Spanish` language." ,
325+ name = Spanish ,
326+ wordlist = spanish,
327+ feature = "spanish" ,
328+ ) ;
413329
414330#[ cfg( test) ]
415331mod tests {
0 commit comments