37 lines
945 B
Rust
Raw Normal View History

//! Binding relations: rows over named (variable) columns.
//!
//! Every operator in this crate (after the initial atom scan) consumes and
//! produces [`Relation`]s. Column names are variable names; a value at column
//! `i` of a row is the value bound to variable `columns[i]` in that solution.
use crate::value::Value;
#[derive(Debug, Clone)]
pub struct Relation {
pub columns: Vec<String>,
pub rows: Vec<Vec<Value>>,
}
impl Relation {
#[must_use]
pub fn new(columns: Vec<String>) -> Self {
Self {
columns,
rows: Vec::new(),
}
}
/// # Panics
/// Panics if `row.len() != self.columns.len()`.
pub fn push(&mut self, row: Vec<Value>) {
assert_eq!(
row.len(),
self.columns.len(),
"row arity mismatch: expected {}, got {}",
self.columns.len(),
row.len(),
);
self.rows.push(row);
}
}