refac: prevent a panic

This commit is contained in:
Dmitriy Pleshevskiy 2022-03-23 23:45:54 +03:00
parent f9c55ce074
commit fac102e6be

View file

@ -1,5 +1,4 @@
use super::StreamCommand; use super::StreamCommand;
use whatlang::{detect};
use crate::result::*; use crate::result::*;
use regex::Regex; use regex::Regex;
@ -35,9 +34,10 @@ impl StreamCommand for QueryCommand<'_> {
} }
// use greyblake/whatlang-rs to autodect locale // use greyblake/whatlang-rs to autodect locale
let text = detect(self.terms).unwrap(); if let Some(info) = whatlang::detect(self.terms) {
if text.confidence() == 1.0 { if info.confidence() == 1.0 {
message.push_str(&format!(" LANG({})", text.lang().code())); message.push_str(&format!(" LANG({})", info.lang().code()));
}
} }
message.push_str("\r\n"); message.push_str("\r\n");