surrealpatch/lib/src/sql/split.rs
2023-11-18 13:56:13 +00:00

48 lines
1.1 KiB
Rust

use crate::sql::fmt::Fmt;
use crate::sql::idiom::Idiom;
use revision::revisioned;
use serde::{Deserialize, Serialize};
use std::fmt::{self, Display, Formatter};
use std::ops::Deref;
#[derive(Clone, Debug, Default, Eq, PartialEq, PartialOrd, Serialize, Deserialize, Hash)]
#[revisioned(revision = 1)]
pub struct Splits(pub Vec<Split>);
impl Deref for Splits {
type Target = Vec<Split>;
fn deref(&self) -> &Self::Target {
&self.0
}
}
impl IntoIterator for Splits {
type Item = Split;
type IntoIter = std::vec::IntoIter<Self::Item>;
fn into_iter(self) -> Self::IntoIter {
self.0.into_iter()
}
}
impl fmt::Display for Splits {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "SPLIT ON {}", Fmt::comma_separated(&self.0))
}
}
#[derive(Clone, Debug, Default, Eq, PartialEq, PartialOrd, Serialize, Deserialize, Hash)]
#[revisioned(revision = 1)]
pub struct Split(pub Idiom);
impl Deref for Split {
type Target = Idiom;
fn deref(&self) -> &Self::Target {
&self.0
}
}
impl Display for Split {
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
Display::fmt(&self.0, f)
}
}