mirror of
https://github.com/meilisearch/MeiliSearch
synced 2025-01-12 14:27:28 +01:00
move the macros to milli
This commit is contained in:
parent
1f54dfa883
commit
9245c89cfe
@ -1,6 +1,9 @@
|
|||||||
use crate::utils::ProcessingBatch;
|
use crate::utils::ProcessingBatch;
|
||||||
use enum_iterator::Sequence;
|
use enum_iterator::Sequence;
|
||||||
use meilisearch_types::milli::progress::{AtomicSubStep, NamedStep, Progress, ProgressView, Step};
|
use meilisearch_types::milli::{
|
||||||
|
make_atomic_progress, make_enum_progress,
|
||||||
|
progress::{AtomicSubStep, NamedStep, Progress, ProgressView, Step},
|
||||||
|
};
|
||||||
use roaring::RoaringBitmap;
|
use roaring::RoaringBitmap;
|
||||||
use std::{borrow::Cow, sync::Arc};
|
use std::{borrow::Cow, sync::Arc};
|
||||||
|
|
||||||
@ -55,50 +58,6 @@ impl ProcessingTasks {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
macro_rules! make_enum_progress {
|
|
||||||
($visibility:vis enum $name:ident { $($variant:ident,)+ }) => {
|
|
||||||
#[repr(u8)]
|
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Sequence)]
|
|
||||||
#[allow(clippy::enum_variant_names)]
|
|
||||||
$visibility enum $name {
|
|
||||||
$($variant),+
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Step for $name {
|
|
||||||
fn name(&self) -> Cow<'static, str> {
|
|
||||||
use convert_case::Casing;
|
|
||||||
|
|
||||||
match self {
|
|
||||||
$(
|
|
||||||
$name::$variant => stringify!($variant).from_case(convert_case::Case::Camel).to_case(convert_case::Case::Lower).into()
|
|
||||||
),+
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn current(&self) -> u32 {
|
|
||||||
*self as u32
|
|
||||||
}
|
|
||||||
|
|
||||||
fn total(&self) -> u32 {
|
|
||||||
Self::CARDINALITY as u32
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
macro_rules! make_atomic_progress {
|
|
||||||
($struct_name:ident alias $atomic_struct_name:ident => $step_name:literal) => {
|
|
||||||
#[derive(Default, Debug, Clone, Copy)]
|
|
||||||
pub struct $struct_name {}
|
|
||||||
impl NamedStep for $struct_name {
|
|
||||||
fn name(&self) -> &'static str {
|
|
||||||
$step_name
|
|
||||||
}
|
|
||||||
}
|
|
||||||
pub type $atomic_struct_name = AtomicSubStep<$struct_name>;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
make_enum_progress! {
|
make_enum_progress! {
|
||||||
pub enum BatchProgress {
|
pub enum BatchProgress {
|
||||||
ProcessingTasks,
|
ProcessingTasks,
|
||||||
|
@ -91,16 +91,53 @@ impl<Name: NamedStep> Step for AtomicSubStep<Name> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Default)]
|
#[macro_export]
|
||||||
pub struct Document {}
|
macro_rules! make_enum_progress {
|
||||||
|
($visibility:vis enum $name:ident { $($variant:ident,)+ }) => {
|
||||||
|
#[repr(u8)]
|
||||||
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, Sequence)]
|
||||||
|
#[allow(clippy::enum_variant_names)]
|
||||||
|
$visibility enum $name {
|
||||||
|
$($variant),+
|
||||||
|
}
|
||||||
|
|
||||||
impl NamedStep for Document {
|
impl Step for $name {
|
||||||
fn name(&self) -> &'static str {
|
fn name(&self) -> Cow<'static, str> {
|
||||||
"document"
|
use convert_case::Casing;
|
||||||
}
|
|
||||||
|
match self {
|
||||||
|
$(
|
||||||
|
$name::$variant => stringify!($variant).from_case(convert_case::Case::Camel).to_case(convert_case::Case::Lower).into()
|
||||||
|
),+
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn current(&self) -> u32 {
|
||||||
|
*self as u32
|
||||||
|
}
|
||||||
|
|
||||||
|
fn total(&self) -> u32 {
|
||||||
|
Self::CARDINALITY as u32
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
pub type AtomicDocumentStep = AtomicSubStep<Document>;
|
#[macro_export]
|
||||||
|
macro_rules! make_atomic_progress {
|
||||||
|
($struct_name:ident alias $atomic_struct_name:ident => $step_name:literal) => {
|
||||||
|
#[derive(Default, Debug, Clone, Copy)]
|
||||||
|
pub struct $struct_name {}
|
||||||
|
impl NamedStep for $struct_name {
|
||||||
|
fn name(&self) -> &'static str {
|
||||||
|
$step_name
|
||||||
|
}
|
||||||
|
}
|
||||||
|
pub type $atomic_struct_name = AtomicSubStep<$struct_name>;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
make_atomic_progress!(Document alias AtomicDocumentStep => "document" );
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Clone)]
|
#[derive(Debug, Serialize, Clone)]
|
||||||
pub struct ProgressView {
|
pub struct ProgressView {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user