diff --git a/data_types/src/lib.rs b/data_types/src/lib.rs index bf3d4cb7e0..07b479f8c1 100644 --- a/data_types/src/lib.rs +++ b/data_types/src/lib.rs @@ -17,7 +17,6 @@ mod database_name; pub mod database_rules; pub mod error; pub mod job; -pub mod non_empty; pub mod partition_metadata; pub mod router; pub mod sequence; diff --git a/data_types/src/non_empty.rs b/data_types/src/non_empty.rs deleted file mode 100644 index a053f060fd..0000000000 --- a/data_types/src/non_empty.rs +++ /dev/null @@ -1,29 +0,0 @@ -use std::ops::Deref; - -/// A string that cannot be empty -/// -/// This is particularly useful for types that map to/from protobuf, where string fields -/// are not nullable - that is they default to an empty string if not specified -#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] -pub struct NonEmptyString(Box); - -impl NonEmptyString { - /// Create a new `NonEmptyString` from the provided `String` - /// - /// Returns None if empty - pub fn new(s: impl Into) -> Option { - let s = s.into(); - match s.is_empty() { - true => None, - false => Some(Self(s.into_boxed_str())), - } - } -} - -impl Deref for NonEmptyString { - type Target = str; - - fn deref(&self) -> &Self::Target { - self.0.as_ref() - } -} diff --git a/data_types2/src/lib.rs b/data_types2/src/lib.rs index ee4d171941..dba8b548fb 100644 --- a/data_types2/src/lib.rs +++ b/data_types2/src/lib.rs @@ -20,13 +20,12 @@ use std::{ convert::TryFrom, fmt::Write, num::{FpCategory, NonZeroU32}, - ops::{Add, Sub}, + ops::{Add, Deref, Sub}, sync::Arc, }; use uuid::Uuid; pub use data_types::{ - non_empty::NonEmptyString, partition_metadata::{ ColumnSummary, InfluxDbType, PartitionAddr, StatValues, Statistics, TableSummary, }, @@ -1255,6 +1254,34 @@ pub fn org_and_bucket_to_database<'a, O: AsRef, B: AsRef>( DatabaseName::new(db_name).context(InvalidDatabaseNameSnafu) } +/// A string that cannot be empty +/// +/// This is particularly useful for types that map to/from protobuf, where string fields +/// are not nullable - that is they default to an empty string if not specified +#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] +pub struct NonEmptyString(Box); + +impl NonEmptyString { + /// Create a new `NonEmptyString` from the provided `String` + /// + /// Returns None if empty + pub fn new(s: impl Into) -> Option { + let s = s.into(); + match s.is_empty() { + true => None, + false => Some(Self(s.into_boxed_str())), + } + } +} + +impl Deref for NonEmptyString { + type Target = str; + + fn deref(&self) -> &Self::Target { + self.0.as_ref() + } +} + #[cfg(test)] mod tests { use super::*; diff --git a/dml/src/lib.rs b/dml/src/lib.rs index 29a6b9e10f..2f33b45887 100644 --- a/dml/src/lib.rs +++ b/dml/src/lib.rs @@ -12,12 +12,11 @@ )] use data_types::{ - non_empty::NonEmptyString, partition_metadata::{StatValues, Statistics}, router::{ShardConfig, ShardId}, sequence::Sequence, }; -use data_types2::DeletePredicate; +use data_types2::{DeletePredicate, NonEmptyString}; use hashbrown::HashMap; use iox_time::Time; use mutable_batch::MutableBatch; @@ -491,7 +490,6 @@ mod tests { use crate::test_util::assert_writes_eq; use data_types::{ consistent_hasher::ConsistentHasher, - non_empty::NonEmptyString, router::{HashRing, Matcher, MatcherToShard}, timestamp::TimestampRange, }; diff --git a/write_buffer/src/codec.rs b/write_buffer/src/codec.rs index 2e318d49a1..84b1ec04ec 100644 --- a/write_buffer/src/codec.rs +++ b/write_buffer/src/codec.rs @@ -1,7 +1,7 @@ //! Encode/Decode for messages use crate::core::WriteBufferError; -use data_types::{non_empty::NonEmptyString, sequence::Sequence}; +use data_types2::{NonEmptyString, Sequence}; use dml::{DmlDelete, DmlMeta, DmlOperation, DmlWrite}; use generated_types::{ google::FromOptionalField,