mirror of
https://github.com/meilisearch/MeiliSearch
synced 2024-11-23 13:24:27 +01:00
Refactoring
This commit is contained in:
parent
a80bb8f77e
commit
3d3ae5aa0c
@ -259,18 +259,18 @@ impl Action {
|
|||||||
("experimental.update", Self::ExperimentalFeaturesUpdate),
|
("experimental.update", Self::ExperimentalFeaturesUpdate),
|
||||||
];
|
];
|
||||||
|
|
||||||
fn ser_action_to_action(v: &str) -> Option<Action> {
|
fn get_action(v: &str) -> Option<Action> {
|
||||||
Self::SERDE_MAP_ARR
|
Self::SERDE_MAP_ARR
|
||||||
.iter()
|
.iter()
|
||||||
.find(|(ser_action, _)| &v == ser_action)
|
.find(|(serde_name, _)| &v == serde_name)
|
||||||
.map(|(_, action)| *action)
|
.map(|(_, action)| *action)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn action_to_ser_action(v: &Action) -> &'static str {
|
fn get_action_serde_name(v: &Action) -> &'static str {
|
||||||
Self::SERDE_MAP_ARR
|
Self::SERDE_MAP_ARR
|
||||||
.iter()
|
.iter()
|
||||||
.find(|(_, ref action)| v == action)
|
.find(|(_, action)| v == action)
|
||||||
.map(|(ser_action, _)| ser_action)
|
.map(|(serde_name, _)| serde_name)
|
||||||
// actions should always have matching serialized values
|
// actions should always have matching serialized values
|
||||||
.unwrap()
|
.unwrap()
|
||||||
}
|
}
|
||||||
@ -326,7 +326,7 @@ impl<E: DeserializeError> Deserr<E> for Action {
|
|||||||
location: deserr::ValuePointerRef<'_>,
|
location: deserr::ValuePointerRef<'_>,
|
||||||
) -> Result<Self, E> {
|
) -> Result<Self, E> {
|
||||||
match value {
|
match value {
|
||||||
deserr::Value::String(s) => match Self::ser_action_to_action(&s) {
|
deserr::Value::String(s) => match Self::get_action(&s) {
|
||||||
Some(action) => Ok(action),
|
Some(action) => Ok(action),
|
||||||
None => Err(deserr::take_cf_content(E::error::<std::convert::Infallible>(
|
None => Err(deserr::take_cf_content(E::error::<std::convert::Infallible>(
|
||||||
None,
|
None,
|
||||||
@ -354,7 +354,7 @@ impl Serialize for Action {
|
|||||||
where
|
where
|
||||||
S: Serializer,
|
S: Serializer,
|
||||||
{
|
{
|
||||||
serializer.serialize_str(Self::action_to_ser_action(self))
|
serializer.serialize_str(Self::get_action_serde_name(self))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -375,7 +375,7 @@ impl<'de> Deserialize<'de> for Action {
|
|||||||
where
|
where
|
||||||
E: serde::de::Error,
|
E: serde::de::Error,
|
||||||
{
|
{
|
||||||
match Self::Value::ser_action_to_action(s) {
|
match Self::Value::get_action(s) {
|
||||||
Some(action) => Ok(action),
|
Some(action) => Ok(action),
|
||||||
None => Err(E::invalid_value(serde::de::Unexpected::Str(s), &"a valid action")),
|
None => Err(E::invalid_value(serde::de::Unexpected::Str(s), &"a valid action")),
|
||||||
}
|
}
|
||||||
|
@ -352,7 +352,7 @@ where
|
|||||||
None,
|
None,
|
||||||
deserr::ErrorKind::Unexpected {
|
deserr::ErrorKind::Unexpected {
|
||||||
msg: format!(
|
msg: format!(
|
||||||
"the distribution sigma must be in the range [0, 1], got {}",
|
"the distribution sigma must be in the range ]0, 1], got {}",
|
||||||
value.sigma
|
value.sigma
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
|
Loading…
Reference in New Issue
Block a user