Skip to main content

interstice_abi/
row.rs

1use crate::IntersticeValue;
2use serde::{Deserialize, Serialize};
3
4#[derive(Debug, Deserialize, Serialize, Clone, PartialEq)]
5pub struct Row {
6    pub primary_key: IntersticeValue,
7    pub entries: Vec<IntersticeValue>,
8}
9impl Into<IntersticeValue> for Row {
10    fn into(mut self) -> IntersticeValue {
11        let mut all_entries = vec![self.primary_key];
12        all_entries.append(&mut self.entries);
13        IntersticeValue::Vec(all_entries)
14    }
15}
16
17impl Into<Row> for IntersticeValue {
18    fn into(self) -> Row {
19        match self {
20            IntersticeValue::Vec(mut vec) => {
21                if vec.len() >= 1 {
22                    let pk = vec.remove(0);
23                    Row {
24                        primary_key: pk,
25                        entries: vec,
26                    }
27                } else {
28                    panic!("Couldn't convert interstice value to row (empty vec)");
29                }
30            }
31            _ => panic!("Couldn't convert interstice value to row (got {:?})", self),
32        }
33    }
34}