2022-02-06 01:14:56 +00:00
|
|
|
use crate::sql::thing::Thing;
|
|
|
|
use crate::sql::value::Value;
|
2022-02-13 19:03:00 +00:00
|
|
|
use std::borrow::Cow;
|
2022-02-06 01:14:56 +00:00
|
|
|
|
|
|
|
#[derive(Clone, Debug, Default, Eq, PartialEq)]
|
2022-02-13 19:03:00 +00:00
|
|
|
pub struct Document<'a> {
|
2022-02-06 01:14:56 +00:00
|
|
|
pub(super) id: Option<Thing>,
|
2022-02-13 19:03:00 +00:00
|
|
|
pub(super) current: Cow<'a, Value>,
|
|
|
|
pub(super) initial: Cow<'a, Value>,
|
2022-02-06 01:14:56 +00:00
|
|
|
}
|
|
|
|
|
2022-02-26 00:34:05 +00:00
|
|
|
impl<'a> Into<Vec<u8>> for &Document<'a> {
|
|
|
|
fn into(self) -> Vec<u8> {
|
|
|
|
msgpack::to_vec(&self.current).unwrap()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-02-13 19:03:00 +00:00
|
|
|
impl<'a> Document<'a> {
|
|
|
|
pub fn new(id: Option<Thing>, val: &'a Value) -> Self {
|
2022-02-06 01:14:56 +00:00
|
|
|
Document {
|
|
|
|
id,
|
2022-02-13 19:03:00 +00:00
|
|
|
current: Cow::Borrowed(val),
|
|
|
|
initial: Cow::Borrowed(val),
|
2022-02-06 01:14:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|