fix: Move NonEmptyString to data_types2

pull/24376/head
Carol (Nichols || Goulding) 2022-05-04 16:57:50 -04:00
parent 6b0e7ae46a
commit 1ea4a40b1f
No known key found for this signature in database
GPG Key ID: E907EE5A736F87D4
5 changed files with 31 additions and 36 deletions

View File

@ -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;

View File

@ -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<str>);
impl NonEmptyString {
/// Create a new `NonEmptyString` from the provided `String`
///
/// Returns None if empty
pub fn new(s: impl Into<String>) -> Option<Self> {
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()
}
}

View File

@ -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<str>, B: AsRef<str>>(
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<str>);
impl NonEmptyString {
/// Create a new `NonEmptyString` from the provided `String`
///
/// Returns None if empty
pub fn new(s: impl Into<String>) -> Option<Self> {
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::*;

View File

@ -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,
};

View File

@ -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,