From 544961372c7b8b0c6bc60b8686ff237e3f8587f3 Mon Sep 17 00:00:00 2001 From: "F. Levi" <55688616+flevi29@users.noreply.github.com> Date: Mon, 21 Oct 2024 00:19:33 +0300 Subject: [PATCH] Attempt pushing bad code in order to stop stuck GitHub action --- meilisearch-types/src/keys.rs | 58 ++++++++++++++++++++++------------- 1 file changed, 36 insertions(+), 22 deletions(-) diff --git a/meilisearch-types/src/keys.rs b/meilisearch-types/src/keys.rs index 0af4be1c1..a6343999f 100644 --- a/meilisearch-types/src/keys.rs +++ b/meilisearch-types/src/keys.rs @@ -2,7 +2,7 @@ use std::convert::Infallible; use std::hash::Hash; use std::str::FromStr; -use bitflags::bitflags; +use bitflags::{bitflags, Flags}; use deserr::{take_cf_content, DeserializeError, Deserr, MergeWithError, ValuePointerRef}; use enum_iterator::Sequence; use milli::update::Setting; @@ -291,15 +291,6 @@ impl Action { .map(|(serde_name, _)| serde_name) .expect("an action is missing a matching serialized value") } - - fn get_index(&self) -> usize { - Self::SERDE_MAP_ARR - .iter() - .enumerate() - .find(|(_, (_, action))| action == self) - .map(|(i, _)| i) - .unwrap() - } } pub mod actions { @@ -409,28 +400,51 @@ impl Sequence for Action { const CARDINALITY: usize = Self::SERDE_MAP_ARR.len(); fn next(&self) -> Option { - let next_index = self.get_index() + 1; - if next_index == Self::CARDINALITY { - None - } else { - Some(Self::SERDE_MAP_ARR[next_index].1) + let mut iter = Self::FLAGS.iter(); + while let Some(action) = iter.next() { + if action.value() == self { + if let Some(action) = iter.next() { + return Some(*action.value()); + } + + break; + } } + + Non } fn previous(&self) -> Option { - let current_index = self.get_index(); - if current_index == 0 { - None - } else { - Some(Self::SERDE_MAP_ARR[current_index - 1].1) + let mut iter = Self::FLAGS.iter().peekable(); + + if let Some(action) = iter.next() { + if action.value() == self { + return None; + } + + if let Some(next_action) = iter.peek() { + if next_action.value() == self { + return Some(*action.value()); + } + } } + + while let Some(action) = iter.next() { + if let Some(next_action) = iter.peek() { + if next_action.value() == self { + return Some(*action.value()); + } + } + } + + None } fn first() -> Option { - Some(Self::SERDE_MAP_ARR[0].1) + Self::FLAGS.first().map(|v| *v.value()) } fn last() -> Option { - Some(Self::SERDE_MAP_ARR[Self::CARDINALITY - 1].1) + Self::FLAGS.last().map(|v| *v.value()) } }