fix: clippy error

This commit is contained in:
Filip Bachul 2023-02-14 00:14:17 +01:00
parent 849de089d2
commit d7ad39ad77
3 changed files with 32 additions and 32 deletions

View File

@ -7,7 +7,7 @@ use serde::{Deserialize, Serialize};
use thiserror::Error;
use crate::error::is_reserved_keyword;
use crate::search::facet::ParseGeoError;
use crate::search::facet::BadGeoError;
use crate::{CriterionError, Error, UserError};
/// This error type is never supposed to be shown to the end user.
@ -15,15 +15,15 @@ use crate::{CriterionError, Error, UserError};
#[derive(Error, Debug)]
pub enum AscDescError {
#[error(transparent)]
GeoError(ParseGeoError),
GeoError(BadGeoError),
#[error("Invalid syntax for the asc/desc parameter: expected expression ending by `:asc` or `:desc`, found `{name}`.")]
InvalidSyntax { name: String },
#[error("`{name}` is a reserved keyword and thus can't be used as a asc/desc rule.")]
ReservedKeyword { name: String },
}
impl From<ParseGeoError> for AscDescError {
fn from(geo_error: ParseGeoError) -> Self {
impl From<BadGeoError> for AscDescError {
fn from(geo_error: BadGeoError) -> Self {
AscDescError::GeoError(geo_error)
}
}
@ -72,9 +72,9 @@ impl FromStr for Member {
.map_err(|_| AscDescError::ReservedKeyword { name: text.to_string() })
})?;
if !(-90.0..=90.0).contains(&lat) {
return Err(ParseGeoError::BadGeoLat(lat))?;
return Err(BadGeoError::Lat(lat))?;
} else if !(-180.0..=180.0).contains(&lng) {
return Err(ParseGeoError::BadGeoLng(lng))?;
return Err(BadGeoError::Lng(lng))?;
}
Ok(Member::Geo([lat, lng]))
}
@ -150,7 +150,7 @@ impl FromStr for AscDesc {
#[derive(Error, Debug)]
pub enum SortError {
#[error(transparent)]
ParseGeoError { error: ParseGeoError },
ParseGeoError { error: BadGeoError },
#[error("Invalid syntax for the geo parameter: expected expression formated like \
`_geoPoint(latitude, longitude)` and ending by `:asc` or `:desc`, found `{name}`.")]
BadGeoPointUsage { name: String },
@ -261,11 +261,11 @@ mod tests {
),
("_geoPoint(35, 85, 75):asc", ReservedKeyword { name: S("_geoPoint(35, 85, 75)") }),
("_geoPoint(18):asc", ReservedKeyword { name: S("_geoPoint(18)") }),
("_geoPoint(200, 200):asc", GeoError(ParseGeoError::BadGeoLat(200.))),
("_geoPoint(90.000001, 0):asc", GeoError(ParseGeoError::BadGeoLat(90.000001))),
("_geoPoint(0, -180.000001):desc", GeoError(ParseGeoError::BadGeoLng(-180.000001))),
("_geoPoint(159.256, 130):asc", GeoError(ParseGeoError::BadGeoLat(159.256))),
("_geoPoint(12, -2021):desc", GeoError(ParseGeoError::BadGeoLng(-2021.))),
("_geoPoint(200, 200):asc", GeoError(BadGeoError::Lat(200.))),
("_geoPoint(90.000001, 0):asc", GeoError(BadGeoError::Lat(90.000001))),
("_geoPoint(0, -180.000001):desc", GeoError(BadGeoError::Lng(-180.000001))),
("_geoPoint(159.256, 130):asc", GeoError(BadGeoError::Lat(159.256))),
("_geoPoint(12, -2021):desc", GeoError(BadGeoError::Lng(-2021.))),
];
for (req, expected_error) in invalid_req {

View File

@ -22,26 +22,26 @@ pub struct Filter<'a> {
}
#[derive(Debug)]
pub enum ParseGeoError {
BadGeoLat(f64),
BadGeoLng(f64),
BadGeoBoundingBoxTopIsBelowBottom(f64, f64),
pub enum BadGeoError {
Lat(f64),
Lng(f64),
BoundingBoxTopIsBelowBottom(f64, f64),
}
impl std::error::Error for ParseGeoError {}
impl std::error::Error for BadGeoError {}
impl Display for ParseGeoError {
impl Display for BadGeoError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::BadGeoBoundingBoxTopIsBelowBottom(top, bottom) => {
Self::BoundingBoxTopIsBelowBottom(top, bottom) => {
write!(f, "The top latitude `{top}` is below the bottom latitude `{bottom}`.")
}
Self::BadGeoLat(lat) => write!(
Self::Lat(lat) => write!(
f,
"Bad latitude `{}`. Latitude must be contained between -90 and 90 degrees. ",
lat
),
Self::BadGeoLng(lng) => write!(
Self::Lng(lng) => write!(
f,
"Bad longitude `{}`. Longitude must be contained between -180 and 180 degrees. ",
lng
@ -53,15 +53,15 @@ impl Display for ParseGeoError {
#[derive(Debug)]
enum FilterError<'a> {
AttributeNotFilterable { attribute: &'a str, filterable_fields: HashSet<String> },
ParseGeoError(ParseGeoError),
ParseGeoError(BadGeoError),
ReservedGeo(&'a str),
Reserved(&'a str),
TooDeep,
}
impl<'a> std::error::Error for FilterError<'a> {}
impl<'a> From<ParseGeoError> for FilterError<'a> {
fn from(geo_error: ParseGeoError) -> Self {
impl<'a> From<BadGeoError> for FilterError<'a> {
fn from(geo_error: BadGeoError) -> Self {
FilterError::ParseGeoError(geo_error)
}
}
@ -390,12 +390,12 @@ impl<'a> Filter<'a> {
[point[0].parse_finite_float()?, point[1].parse_finite_float()?];
if !(-90.0..=90.0).contains(&base_point[0]) {
return Err(
point[0].as_external_error(ParseGeoError::BadGeoLat(base_point[0]))
point[0].as_external_error(BadGeoError::Lat(base_point[0]))
)?;
}
if !(-180.0..=180.0).contains(&base_point[1]) {
return Err(
point[1].as_external_error(ParseGeoError::BadGeoLng(base_point[1]))
point[1].as_external_error(BadGeoError::Lng(base_point[1]))
)?;
}
let radius = radius.parse_finite_float()?;
@ -435,23 +435,23 @@ impl<'a> Filter<'a> {
];
if !(-90.0..=90.0).contains(&top_left[0]) {
return Err(top_left_point[0]
.as_external_error(ParseGeoError::BadGeoLat(top_left[0])))?;
.as_external_error(BadGeoError::Lat(top_left[0])))?;
}
if !(-180.0..=180.0).contains(&top_left[1]) {
return Err(top_left_point[1]
.as_external_error(ParseGeoError::BadGeoLng(top_left[1])))?;
.as_external_error(BadGeoError::Lng(top_left[1])))?;
}
if !(-90.0..=90.0).contains(&bottom_right[0]) {
return Err(bottom_right_point[0]
.as_external_error(ParseGeoError::BadGeoLat(bottom_right[0])))?;
.as_external_error(BadGeoError::Lat(bottom_right[0])))?;
}
if !(-180.0..=180.0).contains(&bottom_right[1]) {
return Err(bottom_right_point[1]
.as_external_error(ParseGeoError::BadGeoLng(bottom_right[1])))?;
.as_external_error(BadGeoError::Lng(bottom_right[1])))?;
}
if top_left[0] < bottom_right[0] {
return Err(bottom_right_point[1].as_external_error(
ParseGeoError::BadGeoBoundingBoxTopIsBelowBottom(
BadGeoError::BoundingBoxTopIsBelowBottom(
top_left[0],
bottom_right[0],
),

View File

@ -4,7 +4,7 @@ use heed::types::{ByteSlice, DecodeIgnore};
use heed::{BytesDecode, RoTxn};
pub use self::facet_distribution::{FacetDistribution, DEFAULT_VALUES_PER_FACET};
pub use self::filter::{Filter, ParseGeoError};
pub use self::filter::{Filter, BadGeoError};
use crate::heed_codec::facet::{FacetGroupKeyCodec, FacetGroupValueCodec};
use crate::heed_codec::ByteSliceRefCodec;
mod facet_distribution;