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