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
29
30
31
32
33
34
//! Tests for the finalized disk format.

use serde::{Deserialize, Serialize};

#[cfg(test)]
mod prop;
#[cfg(test)]
mod snapshot;

/// A formatting struct for raw key-value data
#[derive(Clone, Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Serialize, Deserialize)]
pub struct KV {
    /// The raw key bytes, as a hexadecimal-encoded string.
    k: String,

    /// The raw value bytes, as a hexadecimal-encoded string.
    v: String,
}

impl KV {
    /// Create a new `KV` from raw key-value data.
    pub fn new<K, V>(key: K, value: V) -> KV
    where
        K: AsRef<[u8]>,
        V: AsRef<[u8]>,
    {
        KV::new_hex(hex::encode(key), hex::encode(value))
    }

    /// Create a new `KV` from hex-encoded key-value data.
    pub fn new_hex(key: String, value: String) -> KV {
        KV { k: key, v: value }
    }
}