connectorx/
data_order.rs

1//! This module provides two data orders: row-wise and column-wise for tabular data,
2//! as well as a function to coordinate the data order between source and destination.
3
4use crate::errors::ConnectorXError;
5use fehler::{throw, throws};
6#[derive(Copy, Clone, Eq, PartialEq, Debug)]
7pub enum DataOrder {
8    RowMajor,
9    ColumnMajor,
10}
11
12/// Given the supported data order from source and destination, decide the optimal data order
13/// for producing and writing.
14#[throws(ConnectorXError)]
15pub fn coordinate(src: &[DataOrder], dst: &[DataOrder]) -> DataOrder {
16    assert!(!src.is_empty() && !dst.is_empty());
17
18    match (src, dst) {
19        ([s, ..], [d, ..]) if s == d => *s,
20        ([s, ..], [_, d, ..]) if s == d => *s,
21        ([_, s, ..], [d, ..]) if s == d => *s,
22        _ => throw!(ConnectorXError::CannotResolveDataOrder(
23            src.to_vec(),
24            dst.to_vec()
25        )),
26    }
27}