From 758baeb8e163bf118a6aad989f1ba40da3428434 Mon Sep 17 00:00:00 2001 From: Kerollmops Date: Sat, 5 May 2018 23:22:47 +0200 Subject: [PATCH] feat: Display not utf-8 error results --- src/bin/raptor.rs | 11 ++++++++--- src/lib.rs | 1 - 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/bin/raptor.rs b/src/bin/raptor.rs index f9fe6eca7..20394208e 100644 --- a/src/bin/raptor.rs +++ b/src/bin/raptor.rs @@ -66,9 +66,14 @@ impl<'a> Service for MainService<'a> { body.push_str(""); while let Some((key, values, state)) = stream.next() { - let values = &values[..values.len().min(10)]; - let distance = lev.distance(state); - body.push_str(&format!("

{:?} (dist: {:?}) {:?}

", key, distance, values)); + match std::str::from_utf8(key) { + Ok(key) => { + let values = &values[..values.len().min(10)]; + let distance = lev.distance(state); + body.push_str(&format!("

{:?} (dist: {:?}) {:?}

", key, distance, values)); + }, + Err(e) => eprintln!("{:?}", e), + } } body.push_str(""); diff --git a/src/lib.rs b/src/lib.rs index b50846144..e8eb1397d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -9,7 +9,6 @@ use std::ops::Range; use std::io::{Write, BufReader}; use std::fs::File; use std::path::Path; -use std::str::from_utf8_unchecked; use fst::Automaton; pub use self::fst_map::{FstMap, FstMapBuilder};