Skip to content

Commit 4492649

Browse files
committed
clippy advice
1 parent c9e7bdc commit 4492649

File tree

4 files changed

+49
-55
lines changed

4 files changed

+49
-55
lines changed

src/cmu.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ extern crate pest;
33
use error::Error;
44
use metaphone::{Rule, Word};
55
use pest::Parser;
6-
use reqwest;
7-
use serde_json;
86
use std::collections::HashMap;
97
use std::fs;
108
use std::io::{self, BufRead};
@@ -19,7 +17,7 @@ impl CmuDict {
1917
/// or a directoy containing it. If the dictionary doesn't exisit, it will be
2018
/// downloaded and serialized at the location specified by the path parameter.
2119
pub fn new(path: &str) -> Result<CmuDict, Error> {
22-
match from_json_file(&Path::new(path)) {
20+
match from_json_file(Path::new(path)) {
2321
Ok(d) => Ok(CmuDict { dict: d }),
2422
Err(e) => Err(e),
2523
}
@@ -159,18 +157,16 @@ fn eval_alliteration(phones_a: &[Vec<String>], phones_b: &[Vec<String>]) -> bool
159157
}
160158

161159
fn from_json_file(path: &Path) -> Result<HashMap<String, Vec<Vec<String>>>, Error> {
162-
let dict_json: String;
163-
164160
if !path.exists() {
165161
// regenerate if the file isn't there
166162
if path.is_dir() {
167163
download_and_serialize(&path.join("cmudict.json"))?;
168164
} else {
169-
download_and_serialize(&path)?;
165+
download_and_serialize(path)?;
170166
}
171167
}
172168

173-
dict_json = fs::read_to_string(path)?;
169+
let dict_json = fs::read_to_string(path)?;
174170
let dict: HashMap<String, Vec<Vec<String>>> = serde_json::from_str(&dict_json)?;
175171
Ok(dict)
176172
}

src/error.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
use reqwest;
2-
use serde_json;
31
use std::fmt;
42

53
#[derive(Debug, Clone, PartialEq)]

src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ extern crate pest;
4444
/// assert_eq!(ttaw::metaphone::encoding("detestable").primary, "TTSTPL");
4545
/// assert_eq!(ttaw::metaphone::encoding("detestable").secondary, "TTSTPL");
4646
/// ```
47-
#[macro_use]
4847
extern crate pest_derive;
4948
extern crate reqwest;
5049
extern crate serde_json;

src/metaphone.rs

Lines changed: 46 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ extern crate log;
22
extern crate pest;
33

44
use pest::Parser;
5+
use pest_derive::Parser;
56

67
#[derive(Parser)]
78
#[grammar = "grammar.pest"]
@@ -365,8 +366,8 @@ fn c_case(State { pos, chars, p, s }: &mut State) {
365366
)
366367
.is_err()
367368
&& (chars.get(*pos + 2) != Some(&'E')
368-
|| get_substring(&chars, pos.wrapping_sub(2), *pos + 4) == "BACHER"
369-
|| get_substring(&chars, pos.wrapping_sub(2), *pos + 4) == "MACHER")
369+
|| get_substring(chars, pos.wrapping_sub(2), *pos + 4) == "BACHER"
370+
|| get_substring(chars, pos.wrapping_sub(2), *pos + 4) == "MACHER")
370371
{
371372
*p += "K";
372373
*s += "K";
@@ -375,15 +376,15 @@ fn c_case(State { pos, chars, p, s }: &mut State) {
375376
return;
376377
}
377378

378-
if *pos == 0 && get_substring(&chars, 1, 6) == "AESAR" {
379+
if *pos == 0 && get_substring(chars, 1, 6) == "AESAR" {
379380
*p += "S";
380381
*s += "S";
381382
*pos += 2;
382383

383384
return;
384385
}
385386

386-
if get_substring(&chars, *pos + 1, *pos + 4) == "HIA" {
387+
if get_substring(chars, *pos + 1, *pos + 4) == "HIA" {
387388
*p += "K";
388389
*s += "K";
389390
*pos += 2;
@@ -414,7 +415,7 @@ fn c_case(State { pos, chars, p, s }: &mut State) {
414415
return;
415416
}
416417

417-
if germanic(&chars)
418+
if germanic(chars)
418419
|| Word::parse(
419420
Rule::greek_ch,
420421
get_substring(chars, pos.wrapping_sub(2), *pos + 4).as_str(),
@@ -464,15 +465,15 @@ fn c_case(State { pos, chars, p, s }: &mut State) {
464465
return;
465466
}
466467

467-
if chars.get(*pos + 1) == Some(&'C') && !(*pos == 1 && chars.get(0) == Some(&'M')) {
468+
if chars.get(*pos + 1) == Some(&'C') && !(*pos == 1 && chars.first() == Some(&'M')) {
468469
if (chars.get(*pos + 2) == Some(&'I')
469470
|| chars.get(*pos + 2) == Some(&'E')
470471
|| chars.get(*pos + 2) == Some(&'H'))
471472
&& get_substring(chars, *pos + 2, *pos + 4) != "HU"
472473
{
473474
if (*pos == 1 && chars.get(pos.wrapping_sub(1)) == Some(&'A'))
474-
|| get_substring(&chars, pos.wrapping_sub(1), *pos + 4) == "UCCEE"
475-
|| get_substring(&chars, pos.wrapping_sub(1), *pos + 4) == "UCCES"
475+
|| get_substring(chars, pos.wrapping_sub(1), *pos + 4) == "UCCEE"
476+
|| get_substring(chars, pos.wrapping_sub(1), *pos + 4) == "UCCES"
476477
{
477478
*p += "KS";
478479
*s += "KS";
@@ -584,7 +585,7 @@ fn g_case(State { pos, chars, p, s }: &mut State) {
584585
if *pos > 0
585586
&& Word::parse(
586587
Rule::vowels,
587-
get_char_as_string(&chars, pos.wrapping_sub(1)).as_str(),
588+
get_char_as_string(chars, pos.wrapping_sub(1)).as_str(),
588589
)
589590
.is_err()
590591
{
@@ -627,7 +628,7 @@ fn g_case(State { pos, chars, p, s }: &mut State) {
627628
&& chars.get(pos.wrapping_sub(1)) == Some(&'U')
628629
&& Word::parse(
629630
Rule::g_for_f,
630-
get_char_as_string(&chars, pos.wrapping_sub(3)).as_str(),
631+
get_char_as_string(chars, pos.wrapping_sub(3)).as_str(),
631632
)
632633
.is_ok()
633634
{
@@ -645,14 +646,14 @@ fn g_case(State { pos, chars, p, s }: &mut State) {
645646

646647
if chars.get(*pos + 1) == Some(&'N') {
647648
if *pos == 1
648-
&& Word::parse(Rule::vowels, get_char_as_string(&chars, 0).as_str()).is_ok()
649-
&& !slavo_germanic(&chars)
649+
&& Word::parse(Rule::vowels, get_char_as_string(chars, 0).as_str()).is_ok()
650+
&& !slavo_germanic(chars)
650651
{
651652
*p += "KN";
652653
*s += "N";
653-
} else if get_substring(&chars, *pos + 2, *pos + 4) != "EY"
654+
} else if get_substring(chars, *pos + 2, *pos + 4) != "EY"
654655
&& chars.get(*pos + 1) != Some(&'Y')
655-
&& !slavo_germanic(&chars)
656+
&& !slavo_germanic(chars)
656657
{
657658
*p += "N";
658659
*s += "KN"
@@ -666,7 +667,7 @@ fn g_case(State { pos, chars, p, s }: &mut State) {
666667
return;
667668
}
668669

669-
if get_substring(&chars, *pos + 1, *pos + 3) == "LI" && !slavo_germanic(&chars) {
670+
if get_substring(chars, *pos + 1, *pos + 3) == "LI" && !slavo_germanic(chars) {
670671
*p += "KL";
671672
*s += "L";
672673
*pos += 2;
@@ -677,7 +678,7 @@ fn g_case(State { pos, chars, p, s }: &mut State) {
677678
if *pos == 0
678679
&& Word::parse(
679680
Rule::initial_g_or_for_k_or_j,
680-
get_substring(&chars, 1, 3).as_str(),
681+
get_substring(chars, 1, 3).as_str(),
681682
)
682683
.is_ok()
683684
{
@@ -688,18 +689,18 @@ fn g_case(State { pos, chars, p, s }: &mut State) {
688689
return;
689690
}
690691

691-
if get_substring(&chars, *pos + 1, *pos + 3) == "ER"
692+
if get_substring(chars, *pos + 1, *pos + 3) == "ER"
692693
&& chars.get(pos.wrapping_sub(1)) != Some(&'I')
693694
&& chars.get(pos.wrapping_sub(1)) != Some(&'E')
694695
&& Word::parse(
695696
Rule::initial_anger_exception,
696-
get_substring(&chars, 0, 6).as_str(),
697+
get_substring(chars, 0, 6).as_str(),
697698
)
698699
.is_err()
699700
|| (chars.get(*pos + 1) == Some(&'Y')
700701
&& Word::parse(
701702
Rule::g_for_k_or_j,
702-
get_char_as_string(&chars, pos.wrapping_sub(1)).as_str(),
703+
get_char_as_string(chars, pos.wrapping_sub(1)).as_str(),
703704
)
704705
.is_err())
705706
{
@@ -718,13 +719,13 @@ fn g_case(State { pos, chars, p, s }: &mut State) {
718719
&& chars.get(*pos + 1) == Some(&'G')
719720
&& chars.get(*pos + 2) == Some(&'I'))
720721
{
721-
if get_substring(&chars, *pos + 1, *pos + 3) == "ET" || germanic(&chars) {
722+
if get_substring(chars, *pos + 1, *pos + 3) == "ET" || germanic(chars) {
722723
*p += "K";
723724
*s += "K";
724725
} else {
725726
*p += "J";
726727

727-
if get_substring(&chars, *pos + 1, *pos + 5) == "IER " {
728+
if get_substring(chars, *pos + 1, *pos + 5) == "IER " {
728729
*s += "J";
729730
} else {
730731
*s += "K";
@@ -747,11 +748,11 @@ fn g_case(State { pos, chars, p, s }: &mut State) {
747748
}
748749

749750
fn h_case(State { pos, chars, p, s }: &mut State) {
750-
if Word::parse(Rule::vowels, get_char_as_string(&chars, *pos + 1).as_str()).is_ok()
751+
if Word::parse(Rule::vowels, get_char_as_string(chars, *pos + 1).as_str()).is_ok()
751752
&& (*pos == 0
752753
|| Word::parse(
753754
Rule::vowels,
754-
get_char_as_string(&chars, pos.wrapping_sub(1)).as_str(),
755+
get_char_as_string(chars, pos.wrapping_sub(1)).as_str(),
755756
)
756757
.is_ok())
757758
{
@@ -765,8 +766,8 @@ fn h_case(State { pos, chars, p, s }: &mut State) {
765766
}
766767

767768
fn j_case(State { pos, chars, p, s }: &mut State) {
768-
if get_substring(&chars, *pos, *pos + 4) == "JOSE" || get_substring(&chars, 0, 4) == "SAN " {
769-
if get_substring(&chars, 0, 4) == "SAN " || (*pos == 0 && chars.get(*pos + 4) == Some(&' '))
769+
if get_substring(chars, *pos, *pos + 4) == "JOSE" || get_substring(chars, 0, 4) == "SAN " {
770+
if get_substring(chars, 0, 4) == "SAN " || (*pos == 0 && chars.get(*pos + 4) == Some(&' '))
770771
{
771772
*p += "H";
772773
*s += "H";
@@ -783,11 +784,11 @@ fn j_case(State { pos, chars, p, s }: &mut State) {
783784
if *pos == 0 {
784785
*p += "J";
785786
*s += "A";
786-
} else if !slavo_germanic(&chars)
787+
} else if !slavo_germanic(chars)
787788
&& (chars.get(*pos + 1) == Some(&'A') || chars.get(*pos + 1) == Some(&'O'))
788789
&& Word::parse(
789790
Rule::vowels,
790-
get_char_as_string(&chars, pos.wrapping_sub(1)).as_str(),
791+
get_char_as_string(chars, pos.wrapping_sub(1)).as_str(),
791792
)
792793
.is_ok()
793794
{
@@ -800,7 +801,7 @@ fn j_case(State { pos, chars, p, s }: &mut State) {
800801
&& chars.get(pos.wrapping_sub(1)) != Some(&'L')
801802
&& Word::parse(
802803
Rule::j_for_j_exception,
803-
get_char_as_string(&chars, *pos + 1).as_str(),
804+
get_char_as_string(chars, *pos + 1).as_str(),
804805
)
805806
.is_err()
806807
{
@@ -836,7 +837,7 @@ fn l_case(State { pos, chars, p, s }: &mut State) {
836837
|| Word::parse(
837838
Rule::alle,
838839
get_substring(
839-
&chars,
840+
chars,
840841
chars.len().wrapping_sub(7),
841842
chars.len().wrapping_sub(5),
842843
)
@@ -863,7 +864,7 @@ fn m_case(State { pos, chars, p, s }: &mut State) {
863864
|| (chars.get(pos.wrapping_sub(1)) == Some(&'U')
864865
&& chars.get(*pos + 1) == Some(&'B')
865866
&& (*pos + 1 == chars.len().wrapping_sub(6)
866-
|| get_substring(&chars, *pos + 2, *pos + 4) == "ER"))
867+
|| get_substring(chars, *pos + 2, *pos + 4) == "ER"))
867868
{
868869
*pos += 1;
869870
}
@@ -920,7 +921,7 @@ fn q_case(State { pos, chars, p, s }: &mut State) {
920921

921922
fn r_case(State { pos, chars, p, s }: &mut State) {
922923
if *pos == chars.len().wrapping_sub(6)
923-
&& !slavo_germanic(&chars)
924+
&& !slavo_germanic(chars)
924925
&& chars.get(pos.wrapping_sub(1)) == Some(&'E')
925926
&& chars.get(pos.wrapping_sub(2)) == Some(&'I')
926927
&& chars.get(pos.wrapping_sub(4)) != Some(&'M')
@@ -950,7 +951,7 @@ fn s_case(State { pos, chars, p, s }: &mut State) {
950951
return;
951952
}
952953

953-
if *pos == 0 && get_substring(&chars, 1, 5) == "UGAR" {
954+
if *pos == 0 && get_substring(chars, 1, 5) == "UGAR" {
954955
*p += "X";
955956
*s += "S";
956957
*pos += 1;
@@ -961,7 +962,7 @@ fn s_case(State { pos, chars, p, s }: &mut State) {
961962
if chars.get(*pos + 1) == Some(&'H') {
962963
if Word::parse(
963964
Rule::h_for_s,
964-
get_substring(&chars, *pos + 1, *pos + 5).as_str(),
965+
get_substring(chars, *pos + 1, *pos + 5).as_str(),
965966
)
966967
.is_ok()
967968
{
@@ -979,7 +980,7 @@ fn s_case(State { pos, chars, p, s }: &mut State) {
979980
if chars.get(*pos + 1) == Some(&'I')
980981
&& (chars.get(*pos + 2) == Some(&'O') || chars.get(*pos + 2) == Some(&'A'))
981982
{
982-
if slavo_germanic(&chars) {
983+
if slavo_germanic(chars) {
983984
*p += "S";
984985
*s += "S";
985986
} else {
@@ -1015,12 +1016,12 @@ fn s_case(State { pos, chars, p, s }: &mut State) {
10151016
if chars.get(*pos + 2) == Some(&'H') {
10161017
if Word::parse(
10171018
Rule::dutch_sch,
1018-
get_substring(&chars, *pos + 3, *pos + 5).as_str(),
1019+
get_substring(chars, *pos + 3, *pos + 5).as_str(),
10191020
)
10201021
.is_ok()
10211022
{
1022-
if get_substring(&chars, *pos + 3, *pos + 5) == "ER"
1023-
|| get_substring(&chars, *pos + 3, *pos + 5) == "EN"
1023+
if get_substring(chars, *pos + 3, *pos + 5) == "ER"
1024+
|| get_substring(chars, *pos + 3, *pos + 5) == "EN"
10241025
{
10251026
*p += "X";
10261027
*s += "SK"
@@ -1035,7 +1036,7 @@ fn s_case(State { pos, chars, p, s }: &mut State) {
10351036
}
10361037

10371038
if *pos == 0
1038-
&& Word::parse(Rule::vowels, get_char_as_string(&chars, 3).as_str()).is_err()
1039+
&& Word::parse(Rule::vowels, get_char_as_string(chars, 3).as_str()).is_err()
10391040
&& chars.get(3) != Some(&'W')
10401041
{
10411042
*p += "X";
@@ -1068,8 +1069,8 @@ fn s_case(State { pos, chars, p, s }: &mut State) {
10681069
}
10691070

10701071
if *pos == chars.len().wrapping_sub(6)
1071-
&& (get_substring(&chars, pos.wrapping_sub(2), *pos) == "AI"
1072-
|| get_substring(&chars, pos.wrapping_sub(2), *pos) == "OI")
1072+
&& (get_substring(chars, pos.wrapping_sub(2), *pos) == "AI"
1073+
|| get_substring(chars, pos.wrapping_sub(2), *pos) == "OI")
10731074
{
10741075
*s += "S";
10751076
} else {
@@ -1109,7 +1110,7 @@ fn t_case(State { pos, chars, p, s }: &mut State) {
11091110
if chars.get(*pos + 1) == Some(&'H')
11101111
|| (chars.get(*pos + 1) == Some(&'T') && chars.get(*pos + 2) == Some(&'H'))
11111112
{
1112-
if germanic(&chars)
1113+
if germanic(chars)
11131114
|| ((chars.get(*pos + 2) == Some(&'O') || chars.get(*pos + 2) == Some(&'A'))
11141115
&& chars.get(*pos + 3) == Some(&'M'))
11151116
{
@@ -1154,7 +1155,7 @@ fn w_case(State { pos, chars, p, s }: &mut State) {
11541155
}
11551156

11561157
if *pos == 0 {
1157-
if Word::parse(Rule::vowels, get_char_as_string(&chars, *pos + 1).as_str()).is_ok() {
1158+
if Word::parse(Rule::vowels, get_char_as_string(chars, *pos + 1).as_str()).is_ok() {
11581159
*p += "A";
11591160
*s += "F";
11601161
} else if chars.get(*pos + 1) == Some(&'H') {
@@ -1168,11 +1169,11 @@ fn w_case(State { pos, chars, p, s }: &mut State) {
11681169
&& chars.get(*pos + 1) == Some(&'S')
11691170
&& chars.get(*pos + 2) == Some(&'K')
11701171
&& (chars.get(*pos + 3) == Some(&'I') || chars.get(*pos + 3) == Some(&'Y')))
1171-
|| get_substring(&chars, 0, 3) == "SCH"
1172+
|| get_substring(chars, 0, 3) == "SCH"
11721173
|| (*pos == chars.len().wrapping_sub(6)
11731174
&& Word::parse(
11741175
Rule::vowels,
1175-
get_char_as_string(&chars, pos.wrapping_sub(1)).as_str(),
1176+
get_char_as_string(chars, pos.wrapping_sub(1)).as_str(),
11761177
)
11771178
.is_ok())
11781179
{
@@ -1224,7 +1225,7 @@ fn z_case(State { pos, chars, p, s }: &mut State) {
12241225
&& (chars.get(*pos + 2) == Some(&'A')
12251226
|| chars.get(*pos + 2) == Some(&'I')
12261227
|| chars.get(*pos + 2) == Some(&'O')))
1227-
|| (slavo_germanic(&chars) && *pos > 0 && chars.get(pos.wrapping_sub(1)) != Some(&'T'))
1228+
|| (slavo_germanic(chars) && *pos > 0 && chars.get(pos.wrapping_sub(1)) != Some(&'T'))
12281229
{
12291230
*p += "S";
12301231
*s += "TS"

0 commit comments

Comments
 (0)