feat: Display not utf-8 error results

This commit is contained in:
Kerollmops 2018-05-05 23:22:47 +02:00 committed by Clément Renault
parent 0f9ada1c4e
commit 758baeb8e1
2 changed files with 8 additions and 4 deletions

View File

@ -66,9 +66,14 @@ impl<'a> Service for MainService<'a> {
body.push_str("<html><body>"); body.push_str("<html><body>");
while let Some((key, values, state)) = stream.next() { while let Some((key, values, state)) = stream.next() {
let values = &values[..values.len().min(10)]; match std::str::from_utf8(key) {
let distance = lev.distance(state); Ok(key) => {
body.push_str(&format!("<p>{:?} (dist: {:?}) {:?}</p>", key, distance, values)); let values = &values[..values.len().min(10)];
let distance = lev.distance(state);
body.push_str(&format!("<p>{:?} (dist: {:?}) {:?}</p>", key, distance, values));
},
Err(e) => eprintln!("{:?}", e),
}
} }
body.push_str("</body></html>"); body.push_str("</body></html>");

View File

@ -9,7 +9,6 @@ use std::ops::Range;
use std::io::{Write, BufReader}; use std::io::{Write, BufReader};
use std::fs::File; use std::fs::File;
use std::path::Path; use std::path::Path;
use std::str::from_utf8_unchecked;
use fst::Automaton; use fst::Automaton;
pub use self::fst_map::{FstMap, FstMapBuilder}; pub use self::fst_map::{FstMap, FstMapBuilder};