Skip to content

Commit 0c26f0e

Browse files
committed
Improved example [skip ci]
1 parent 5f51d5c commit 0c26f0e

File tree

1 file changed

+4
-9
lines changed

1 file changed

+4
-9
lines changed

examples/disco/src/main.rs

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -69,19 +69,14 @@ fn load_movielens(path: &Path) -> Result<Dataset<i32, String>, Box<dyn Error>> {
6969
// read movies, removing invalid UTF-8 bytes
7070
let mut movies = HashMap::with_capacity(2000);
7171
let movies_file = File::open(path.join("u.item"))?;
72-
let mut rdr = BufReader::new(movies_file);
73-
let mut buf = Vec::new();
74-
loop {
75-
let bytes_read = rdr.read_until(b'\n', &mut buf)?;
76-
if bytes_read == 0 {
77-
break;
78-
}
79-
let line = String::from_utf8_lossy(&buf);
72+
let rdr = BufReader::new(movies_file);
73+
for line in rdr.split(b'\n') {
74+
let line = line?;
75+
let line = String::from_utf8_lossy(&line);
8076
let mut row = line.split('|');
8177
let id = row.next().unwrap().to_string();
8278
let name = row.next().unwrap().to_string();
8379
movies.insert(id, name);
84-
buf.clear();
8580
}
8681

8782
// read ratings and create dataset

0 commit comments

Comments
 (0)