1use {
2 crate::{data::Value, result::Result},
3 serde::{Deserialize, Serialize},
4 std::fmt::Debug,
5 thiserror::Error,
6};
7
8#[derive(Error, Serialize, Debug, PartialEq)]
9pub enum RowError {
10 #[error("conflict! row cannot be empty")]
11 ConflictOnEmptyRow,
12}
13
14#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
15pub struct Row(pub Vec<Value>);
16
17impl Row {
18 pub fn get_value(&self, index: usize) -> Option<&Value> {
19 self.0.get(index)
20 }
21
22 pub fn take_first_value(self) -> Result<Value> {
23 self.0
24 .into_iter()
25 .next()
26 .ok_or_else(|| RowError::ConflictOnEmptyRow.into())
27 }
28}