fix: Move NonEmptyString to data_types2
parent
6b0e7ae46a
commit
1ea4a40b1f
|
@ -17,7 +17,6 @@ mod database_name;
|
||||||
pub mod database_rules;
|
pub mod database_rules;
|
||||||
pub mod error;
|
pub mod error;
|
||||||
pub mod job;
|
pub mod job;
|
||||||
pub mod non_empty;
|
|
||||||
pub mod partition_metadata;
|
pub mod partition_metadata;
|
||||||
pub mod router;
|
pub mod router;
|
||||||
pub mod sequence;
|
pub mod sequence;
|
||||||
|
|
|
@ -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()
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -20,13 +20,12 @@ use std::{
|
||||||
convert::TryFrom,
|
convert::TryFrom,
|
||||||
fmt::Write,
|
fmt::Write,
|
||||||
num::{FpCategory, NonZeroU32},
|
num::{FpCategory, NonZeroU32},
|
||||||
ops::{Add, Sub},
|
ops::{Add, Deref, Sub},
|
||||||
sync::Arc,
|
sync::Arc,
|
||||||
};
|
};
|
||||||
use uuid::Uuid;
|
use uuid::Uuid;
|
||||||
|
|
||||||
pub use data_types::{
|
pub use data_types::{
|
||||||
non_empty::NonEmptyString,
|
|
||||||
partition_metadata::{
|
partition_metadata::{
|
||||||
ColumnSummary, InfluxDbType, PartitionAddr, StatValues, Statistics, TableSummary,
|
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)
|
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)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
|
@ -12,12 +12,11 @@
|
||||||
)]
|
)]
|
||||||
|
|
||||||
use data_types::{
|
use data_types::{
|
||||||
non_empty::NonEmptyString,
|
|
||||||
partition_metadata::{StatValues, Statistics},
|
partition_metadata::{StatValues, Statistics},
|
||||||
router::{ShardConfig, ShardId},
|
router::{ShardConfig, ShardId},
|
||||||
sequence::Sequence,
|
sequence::Sequence,
|
||||||
};
|
};
|
||||||
use data_types2::DeletePredicate;
|
use data_types2::{DeletePredicate, NonEmptyString};
|
||||||
use hashbrown::HashMap;
|
use hashbrown::HashMap;
|
||||||
use iox_time::Time;
|
use iox_time::Time;
|
||||||
use mutable_batch::MutableBatch;
|
use mutable_batch::MutableBatch;
|
||||||
|
@ -491,7 +490,6 @@ mod tests {
|
||||||
use crate::test_util::assert_writes_eq;
|
use crate::test_util::assert_writes_eq;
|
||||||
use data_types::{
|
use data_types::{
|
||||||
consistent_hasher::ConsistentHasher,
|
consistent_hasher::ConsistentHasher,
|
||||||
non_empty::NonEmptyString,
|
|
||||||
router::{HashRing, Matcher, MatcherToShard},
|
router::{HashRing, Matcher, MatcherToShard},
|
||||||
timestamp::TimestampRange,
|
timestamp::TimestampRange,
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
//! Encode/Decode for messages
|
//! Encode/Decode for messages
|
||||||
|
|
||||||
use crate::core::WriteBufferError;
|
use crate::core::WriteBufferError;
|
||||||
use data_types::{non_empty::NonEmptyString, sequence::Sequence};
|
use data_types2::{NonEmptyString, Sequence};
|
||||||
use dml::{DmlDelete, DmlMeta, DmlOperation, DmlWrite};
|
use dml::{DmlDelete, DmlMeta, DmlOperation, DmlWrite};
|
||||||
use generated_types::{
|
use generated_types::{
|
||||||
google::FromOptionalField,
|
google::FromOptionalField,
|
||||||
|
|
Loading…
Reference in New Issue