use super::{Collection, Field, Index, Kind};
impl Kind {
#[must_use]
pub fn any() -> Self {
Self {
bytes: Some(()),
integer: Some(()),
float: Some(()),
boolean: Some(()),
timestamp: Some(()),
regex: Some(()),
null: Some(()),
undefined: Some(()),
array: Some(Collection::any()),
object: Some(Collection::any()),
}
}
#[must_use]
pub fn json() -> Self {
Self {
bytes: Some(()),
integer: Some(()),
float: Some(()),
boolean: Some(()),
timestamp: None,
regex: None,
null: Some(()),
undefined: None,
array: Some(Collection::json()),
object: Some(Collection::json()),
}
}
#[must_use]
pub const fn bytes() -> Self {
Self {
bytes: Some(()),
integer: None,
float: None,
boolean: None,
timestamp: None,
regex: None,
null: None,
undefined: None,
array: None,
object: None,
}
}
#[must_use]
pub const fn integer() -> Self {
Self {
bytes: None,
integer: Some(()),
float: None,
boolean: None,
timestamp: None,
regex: None,
null: None,
undefined: None,
array: None,
object: None,
}
}
#[must_use]
pub const fn float() -> Self {
Self {
bytes: None,
integer: None,
float: Some(()),
boolean: None,
timestamp: None,
regex: None,
null: None,
undefined: None,
array: None,
object: None,
}
}
#[must_use]
pub const fn boolean() -> Self {
Self {
bytes: None,
integer: None,
float: None,
boolean: Some(()),
timestamp: None,
regex: None,
null: None,
undefined: None,
array: None,
object: None,
}
}
#[must_use]
pub const fn timestamp() -> Self {
Self {
bytes: None,
integer: None,
float: None,
boolean: None,
timestamp: Some(()),
regex: None,
null: None,
undefined: None,
array: None,
object: None,
}
}
#[must_use]
pub const fn regex() -> Self {
Self {
bytes: None,
integer: None,
float: None,
boolean: None,
timestamp: None,
regex: Some(()),
null: None,
undefined: None,
array: None,
object: None,
}
}
#[must_use]
pub const fn null() -> Self {
Self {
bytes: None,
integer: None,
float: None,
boolean: None,
timestamp: None,
regex: None,
null: Some(()),
undefined: None,
array: None,
object: None,
}
}
#[must_use]
pub const fn undefined() -> Self {
Self {
bytes: None,
integer: None,
float: None,
boolean: None,
timestamp: None,
regex: None,
null: None,
undefined: Some(()),
array: None,
object: None,
}
}
#[must_use]
pub const fn never() -> Self {
Self {
bytes: None,
integer: None,
float: None,
boolean: None,
timestamp: None,
regex: None,
null: None,
undefined: None,
array: None,
object: None,
}
}
#[must_use]
pub fn array(collection: impl Into<Collection<Index>>) -> Self {
Self {
bytes: None,
integer: None,
float: None,
boolean: None,
timestamp: None,
regex: None,
null: None,
undefined: None,
array: Some(collection.into()),
object: None,
}
}
#[must_use]
pub fn object(collection: impl Into<Collection<Field>>) -> Self {
Self {
bytes: None,
integer: None,
float: None,
boolean: None,
timestamp: None,
regex: None,
null: None,
undefined: None,
array: None,
object: Some(collection.into()),
}
}
#[must_use]
pub fn any_object() -> Self {
Self::object(Collection::any())
}
}
impl Kind {
#[must_use]
pub const fn or_bytes(mut self) -> Self {
self.bytes = Some(());
self
}
#[must_use]
pub const fn or_integer(mut self) -> Self {
self.integer = Some(());
self
}
#[must_use]
pub const fn or_float(mut self) -> Self {
self.float = Some(());
self
}
#[must_use]
pub const fn or_boolean(mut self) -> Self {
self.boolean = Some(());
self
}
#[must_use]
pub const fn or_timestamp(mut self) -> Self {
self.timestamp = Some(());
self
}
#[must_use]
pub const fn or_regex(mut self) -> Self {
self.regex = Some(());
self
}
#[must_use]
pub const fn or_null(mut self) -> Self {
self.null = Some(());
self
}
#[must_use]
pub const fn or_undefined(mut self) -> Self {
self.undefined = Some(());
self
}
#[must_use]
pub fn or_array(mut self, collection: impl Into<Collection<Index>>) -> Self {
self.array = Some(collection.into());
self
}
#[must_use]
pub fn or_object(mut self, collection: impl Into<Collection<Field>>) -> Self {
self.object = Some(collection.into());
self
}
}
impl Kind {
pub fn add_bytes(&mut self) -> bool {
self.bytes.replace(()).is_none()
}
pub fn add_integer(&mut self) -> bool {
self.integer.replace(()).is_none()
}
pub fn add_float(&mut self) -> bool {
self.float.replace(()).is_none()
}
pub fn add_boolean(&mut self) -> bool {
self.boolean.replace(()).is_none()
}
pub fn add_timestamp(&mut self) -> bool {
self.timestamp.replace(()).is_none()
}
pub fn add_regex(&mut self) -> bool {
self.regex.replace(()).is_none()
}
pub fn add_null(&mut self) -> bool {
self.null.replace(()).is_none()
}
pub fn add_undefined(&mut self) -> bool {
self.undefined.replace(()).is_none()
}
pub fn add_array(&mut self, collection: impl Into<Collection<Index>>) -> bool {
self.array.replace(collection.into()).is_none()
}
pub fn add_object(&mut self, collection: impl Into<Collection<Field>>) -> bool {
self.object.replace(collection.into()).is_none()
}
}
impl Kind {
pub fn remove_bytes(&mut self) -> bool {
self.bytes.take().is_some()
}
pub fn remove_integer(&mut self) -> bool {
self.integer.take().is_some()
}
pub fn remove_float(&mut self) -> bool {
self.float.take().is_some()
}
pub fn remove_boolean(&mut self) -> bool {
self.boolean.take().is_some()
}
pub fn remove_timestamp(&mut self) -> bool {
self.timestamp.take().is_some()
}
pub fn remove_regex(&mut self) -> bool {
self.regex.take().is_some()
}
pub fn remove_null(&mut self) -> bool {
self.null.take().is_some()
}
pub fn remove_undefined(&mut self) -> bool {
self.undefined.take().is_some()
}
pub fn remove_array(&mut self) -> bool {
self.array.take().is_some()
}
pub fn remove_object(&mut self) -> bool {
self.object.take().is_some()
}
}
impl Kind {
#[must_use]
pub fn without_undefined(&self) -> Self {
let mut kind = self.clone();
kind.remove_undefined();
kind
}
#[must_use]
pub fn without_array(&self) -> Self {
let mut kind = self.clone();
kind.remove_array();
kind
}
#[must_use]
pub fn without_object(&self) -> Self {
let mut kind = self.clone();
kind.remove_object();
kind
}
}