Skip to content

Commit

Permalink
Behavior-preserving refactor of Value into a module. (#510)
Browse files Browse the repository at this point in the history
  • Loading branch information
jpschorr committed Oct 22, 2024
1 parent b64e8b7 commit 75ffa06
Show file tree
Hide file tree
Showing 7 changed files with 434 additions and 425 deletions.
3 changes: 2 additions & 1 deletion partiql-value/src/bag.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ use std::hash::{Hash, Hasher};

use std::{slice, vec};

use crate::{EqualityValue, List, NullSortedValue, NullableEq, Value};
use crate::sort::NullSortedValue;
use crate::{EqualityValue, List, NullableEq, Value};
#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};

Expand Down
70 changes: 70 additions & 0 deletions partiql-value/src/bindings.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
use crate::{PairsIntoIter, PairsIter, Value};
#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};
use std::borrow::Cow;
use std::iter::Once;

#[derive(Clone, Hash, Debug, Eq, PartialEq)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub enum BindingsName<'s> {
CaseSensitive(Cow<'s, str>),
CaseInsensitive(Cow<'s, str>),
}

#[derive(Debug, Clone)]
pub enum BindingIter<'a> {
Tuple(PairsIter<'a>),
Single(Once<&'a Value>),
Empty,
}

impl<'a> Iterator for BindingIter<'a> {
type Item = (Option<&'a String>, &'a Value);

#[inline]
fn next(&mut self) -> Option<Self::Item> {
match self {
BindingIter::Tuple(t) => t.next().map(|(k, v)| (Some(k), v)),
BindingIter::Single(single) => single.next().map(|v| (None, v)),
BindingIter::Empty => None,
}
}

#[inline]
fn size_hint(&self) -> (usize, Option<usize>) {
match self {
BindingIter::Tuple(t) => t.size_hint(),
BindingIter::Single(_single) => (1, Some(1)),
BindingIter::Empty => (0, Some(0)),
}
}
}

#[derive(Debug)]
pub enum BindingIntoIter {
Tuple(PairsIntoIter),
Single(Once<Value>),
Empty,
}

impl Iterator for BindingIntoIter {
type Item = (Option<String>, Value);

#[inline]
fn next(&mut self) -> Option<Self::Item> {
match self {
BindingIntoIter::Tuple(t) => t.next().map(|(k, v)| (Some(k), v)),
BindingIntoIter::Single(single) => single.next().map(|v| (None, v)),
BindingIntoIter::Empty => None,
}
}

#[inline]
fn size_hint(&self) -> (usize, Option<usize>) {
match self {
BindingIntoIter::Tuple(t) => t.size_hint(),
BindingIntoIter::Single(_single) => (1, Some(1)),
BindingIntoIter::Empty => (0, Some(0)),
}
}
}
Loading

0 comments on commit 75ffa06

Please sign in to comment.