From 378deb0bef48269ee373fc3a6426e24c80393b2e Mon Sep 17 00:00:00 2001 From: Louis Dureuil Date: Mon, 13 Nov 2023 13:37:58 +0100 Subject: [PATCH] Rename trait --- milli/src/documents/mod.rs | 6 ++---- milli/src/documents/primary_key.rs | 10 +++++++--- milli/src/fields_ids_map.rs | 2 +- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/milli/src/documents/mod.rs b/milli/src/documents/mod.rs index 4429f083d..a874ac17e 100644 --- a/milli/src/documents/mod.rs +++ b/milli/src/documents/mod.rs @@ -12,9 +12,7 @@ use bimap::BiHashMap; pub use builder::DocumentsBatchBuilder; pub use enriched::{EnrichedDocument, EnrichedDocumentsBatchCursor, EnrichedDocumentsBatchReader}; use obkv::KvReader; -pub use primary_key::{ - DocumentIdExtractionError, FieldDistribution, PrimaryKey, DEFAULT_PRIMARY_KEY, -}; +pub use primary_key::{DocumentIdExtractionError, FieldIdMapper, PrimaryKey, DEFAULT_PRIMARY_KEY}; pub use reader::{DocumentsBatchCursor, DocumentsBatchCursorError, DocumentsBatchReader}; use serde::{Deserialize, Serialize}; @@ -91,7 +89,7 @@ impl DocumentsBatchIndex { } } -impl FieldDistribution for DocumentsBatchIndex { +impl FieldIdMapper for DocumentsBatchIndex { fn id(&self, name: &str) -> Option { self.id(name) } diff --git a/milli/src/documents/primary_key.rs b/milli/src/documents/primary_key.rs index dd97f2608..16a95c21f 100644 --- a/milli/src/documents/primary_key.rs +++ b/milli/src/documents/primary_key.rs @@ -11,7 +11,11 @@ const PRIMARY_KEY_SPLIT_SYMBOL: char = '.'; /// The default primary that is used when not specified. pub const DEFAULT_PRIMARY_KEY: &str = "id"; -pub trait FieldDistribution { +/// Trait for objects that can map the name of a field to its [`FieldId`]. +pub trait FieldIdMapper { + /// Attempts to map the passed name to its [`FieldId`]. + /// + /// `None` if the field with this name was not found. fn id(&self, name: &str) -> Option; } @@ -30,7 +34,7 @@ pub enum DocumentIdExtractionError { } impl<'a> PrimaryKey<'a> { - pub fn new(path: &'a str, fields: &impl FieldDistribution) -> Option { + pub fn new(path: &'a str, fields: &impl FieldIdMapper) -> Option { Some(if path.contains(PRIMARY_KEY_SPLIT_SYMBOL) { Self::Nested { name: path } } else { @@ -49,7 +53,7 @@ impl<'a> PrimaryKey<'a> { pub fn document_id( &self, document: &obkv::KvReader, - fields: &impl FieldDistribution, + fields: &impl FieldIdMapper, ) -> Result> { match self { PrimaryKey::Flat { name: _, field_id } => match document.get(*field_id) { diff --git a/milli/src/fields_ids_map.rs b/milli/src/fields_ids_map.rs index 85320c168..9c1c87f82 100644 --- a/milli/src/fields_ids_map.rs +++ b/milli/src/fields_ids_map.rs @@ -81,7 +81,7 @@ impl Default for FieldsIdsMap { } } -impl crate::documents::FieldDistribution for FieldsIdsMap { +impl crate::documents::FieldIdMapper for FieldsIdsMap { fn id(&self, name: &str) -> Option { self.id(name) }