lightning_storage_server/
model.rs1use serde::{Deserialize, Serialize};
2use std::fmt::{Debug, Formatter};
3
4use crate::proto;
5
6#[derive(Serialize, Deserialize, Clone)]
7pub struct Value {
8 pub version: i64,
12 pub value: Vec<u8>,
16}
17
18impl Debug for Value {
19 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
20 f.debug_struct("Value")
21 .field("version", &self.version)
22 .field(
24 "value",
25 &String::from_utf8(self.value.clone()).unwrap_or_else(|_| hex::encode(&self.value)),
26 )
27 .finish()
28 }
29}
30
31impl Into<(String, Value)> for proto::KeyValue {
32 fn into(self) -> (String, Value) {
33 (self.key, Value { version: self.version, value: self.value })
34 }
35}
36
37impl Into<proto::KeyValue> for (String, Option<Value>) {
39 fn into(self) -> proto::KeyValue {
40 let (key, v) = self;
41 let version = v.as_ref().map(|v| v.version).unwrap_or(-1);
42 let value = v.as_ref().map(|v| v.value.clone()).unwrap_or_default();
43 proto::KeyValue { key, version, value }
44 }
45}
46
47impl Into<proto::KeyValue> for (String, Value) {
49 fn into(self) -> proto::KeyValue {
50 let (key, v) = self;
51 proto::KeyValue { key, version: v.version, value: v.value }
52 }
53}