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),
|
||||
];
|
||||
|
||||
fn ser_action_to_action(v: &str) -> Option<Action> {
|
||||
fn get_action(v: &str) -> Option<Action> {
|
||||
Self::SERDE_MAP_ARR
|
||||
.iter()
|
||||
.find(|(ser_action, _)| &v == ser_action)
|
||||
.find(|(serde_name, _)| &v == serde_name)
|
||||
.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
|
||||
.iter()
|
||||
.find(|(_, ref action)| v == action)
|
||||
.map(|(ser_action, _)| ser_action)
|
||||
.find(|(_, action)| v == action)
|
||||
.map(|(serde_name, _)| serde_name)
|
||||
// actions should always have matching serialized values
|
||||
.unwrap()
|
||||
}
|
||||
@ -326,7 +326,7 @@ impl<E: DeserializeError> Deserr<E> for Action {
|
||||
location: deserr::ValuePointerRef<'_>,
|
||||
) -> Result<Self, E> {
|
||||
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),
|
||||
None => Err(deserr::take_cf_content(E::error::<std::convert::Infallible>(
|
||||
None,
|
||||
@ -354,7 +354,7 @@ impl Serialize for Action {
|
||||
where
|
||||
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
|
||||
E: serde::de::Error,
|
||||
{
|
||||
match Self::Value::ser_action_to_action(s) {
|
||||
match Self::Value::get_action(s) {
|
||||
Some(action) => Ok(action),
|
||||
None => Err(E::invalid_value(serde::de::Unexpected::Str(s), &"a valid action")),
|
||||
}
|
||||
|
@ -352,7 +352,7 @@ where
|
||||
None,
|
||||
deserr::ErrorKind::Unexpected {
|
||||
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
|
||||
),
|
||||
},
|
||||
|
Loading…
Reference in New Issue
Block a user