mirror of
https://github.com/meilisearch/MeiliSearch
synced 2025-07-04 20:37:15 +02:00
Move crates under a sub folder to clean up the code
This commit is contained in:
parent
30f3c30389
commit
9c1e54a2c8
1062 changed files with 19 additions and 20 deletions
56
crates/milli/src/facet/facet_value.rs
Normal file
56
crates/milli/src/facet/facet_value.rs
Normal file
|
@ -0,0 +1,56 @@
|
|||
use ordered_float::OrderedFloat;
|
||||
use serde::{Serialize, Serializer};
|
||||
|
||||
#[derive(Debug, Clone, PartialOrd, Ord, PartialEq, Eq, Hash)]
|
||||
pub enum FacetValue {
|
||||
String(String),
|
||||
Number(OrderedFloat<f64>),
|
||||
}
|
||||
|
||||
impl From<String> for FacetValue {
|
||||
fn from(string: String) -> FacetValue {
|
||||
FacetValue::String(string)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<&str> for FacetValue {
|
||||
fn from(string: &str) -> FacetValue {
|
||||
FacetValue::String(string.to_owned())
|
||||
}
|
||||
}
|
||||
|
||||
impl From<f64> for FacetValue {
|
||||
fn from(float: f64) -> FacetValue {
|
||||
FacetValue::Number(OrderedFloat(float))
|
||||
}
|
||||
}
|
||||
|
||||
impl From<OrderedFloat<f64>> for FacetValue {
|
||||
fn from(float: OrderedFloat<f64>) -> FacetValue {
|
||||
FacetValue::Number(float)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<i64> for FacetValue {
|
||||
fn from(integer: i64) -> FacetValue {
|
||||
FacetValue::Number(OrderedFloat(integer as f64))
|
||||
}
|
||||
}
|
||||
|
||||
/// We implement Serialize ourselves because we need to always serialize it as a string,
|
||||
/// JSON object keys must be strings not numbers.
|
||||
// TODO remove this impl and convert them into string, by hand, when required.
|
||||
impl Serialize for FacetValue {
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
S: Serializer,
|
||||
{
|
||||
match self {
|
||||
FacetValue::String(string) => serializer.serialize_str(string),
|
||||
FacetValue::Number(number) => {
|
||||
let string = number.to_string();
|
||||
serializer.serialize_str(&string)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue