Skip to content

Commit

Permalink
nix AlgebraicValue::ArrayOf
Browse files Browse the repository at this point in the history
  • Loading branch information
Centril committed Oct 9, 2023
1 parent 0ddbb4d commit 8617bc0
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 22 deletions.
5 changes: 2 additions & 3 deletions crates/bench/src/spacetime_module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,9 +150,8 @@ impl BenchDatabase for SpacetimeModule {
}

fn insert_bulk<T: BenchTable>(&mut self, table_id: &Self::TableId, rows: Vec<T>) -> ResultBench<()> {
let args = product![AlgebraicValue::ArrayOf(ArrayValue::Product(
rows.into_iter().map(|row| row.into_product_value()).collect(),
))];
let rows = rows.into_iter().map(|row| row.into_product_value()).collect();
let args = product![ArrayValue::Product(rows)];
let SpacetimeModule { runtime, module } = self;
let module = module.as_mut().unwrap();
let reducer_name = format!("insert_bulk_{}", table_id.snake_case);
Expand Down
16 changes: 8 additions & 8 deletions crates/core/src/db/datastore/system_tables.rs
Original file line number Diff line number Diff line change
Expand Up @@ -796,11 +796,11 @@ impl<'a> TryFrom<&'a ProductValue> for StIndexRow<&'a str> {
impl<Name: AsRef<str>> From<&StIndexRow<Name>> for ProductValue {
fn from(x: &StIndexRow<Name>) -> Self {
product![
AlgebraicValue::U32(x.index_id),
AlgebraicValue::U32(x.table_id),
AlgebraicValue::ArrayOf(x.cols.clone()),
x.index_id,
x.table_id,
ArrayValue::from(x.cols.clone()),
AlgebraicValue::String(x.index_name.as_ref().to_string()),
AlgebraicValue::Bool(x.is_unique)
x.is_unique
]
}
}
Expand Down Expand Up @@ -941,11 +941,11 @@ impl<'a> TryFrom<&'a ProductValue> for StConstraintRow<&'a str> {
impl<Name: AsRef<str>> From<&StConstraintRow<Name>> for ProductValue {
fn from(x: &StConstraintRow<Name>) -> Self {
product![
AlgebraicValue::U32(x.constraint_id),
x.constraint_id,
AlgebraicValue::String(x.constraint_name.as_ref().to_string()),
AlgebraicValue::U8(x.kind.bits()),
AlgebraicValue::U32(x.table_id),
AlgebraicValue::ArrayOf(x.columns.clone())
x.kind.bits(),
x.table_id,
ArrayValue::from(x.columns.clone())
]
}
}
Expand Down
10 changes: 2 additions & 8 deletions crates/sats/src/algebraic_value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,12 +141,6 @@ impl AlgebraicValue {
}
}

/// Returns an [`AlgebraicValue`] for a `val` which can be converted into an [`ArrayValue`].
#[inline]
pub fn ArrayOf(val: impl Into<ArrayValue>) -> Self {
Self::Array(val.into())
}

/// Returns an [`AlgebraicValue`] for `some: v`.
///
/// The `some` variant is assigned the tag `0`.
Expand Down Expand Up @@ -307,15 +301,15 @@ mod tests {
#[test]
fn array() {
let array = AlgebraicType::array(AlgebraicType::U8);
let value = AlgebraicValue::ArrayOf(ArrayValue::Sum(Vec::new()));
let value = AlgebraicValue::Array(ArrayValue::Sum(Vec::new()));
let typespace = Typespace::new(vec![]);
assert_eq!(in_space(&typespace, &array, &value).to_satn(), "[]");
}

#[test]
fn array_of_values() {
let array = AlgebraicType::array(AlgebraicType::U8);
let value = AlgebraicValue::ArrayOf(vec![3u8]);
let value = AlgebraicValue::Array([3u8].into());
let typespace = Typespace::new(vec![]);
assert_eq!(in_space(&typespace, &array, &value).to_satn(), "[3]");
}
Expand Down
2 changes: 1 addition & 1 deletion crates/sats/src/algebraic_value/ser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ impl ser::SerializeArray for SerializeArrayValue {

fn end(self) -> Result<Self::Ok, Self::Error> {
let array: ArrayValue = self.array.try_into().unwrap_or_else(|e| match e {});
Ok(AlgebraicValue::ArrayOf(array))
Ok(array.into())
}
}

Expand Down
2 changes: 1 addition & 1 deletion crates/sats/src/convert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ impl From<SumValue> for AlgebraicValue {

impl From<ArrayValue> for AlgebraicValue {
fn from(x: ArrayValue) -> Self {
Self::ArrayOf(x)
Self::Array(x)
}
}

Expand Down
2 changes: 1 addition & 1 deletion crates/sats/tests/encoding_roundtrip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ fn array_value<T>(vec: Vec<T>) -> AlgebraicValue
where
ArrayValue: From<Vec<T>>,
{
AlgebraicValue::ArrayOf(vec)
AlgebraicValue::Array(vec.into())
}

fn array_values() -> impl Strategy<Value = AlgebraicValue> {
Expand Down

0 comments on commit 8617bc0

Please sign in to comment.