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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
//! Mapper and mapped key-value types

use crate::range::Range;
use crate::tuple::Tuple;
use crate::KeyValue;

/// [`Mapper`] represents the behaviour of a mapped range read.
///
/// [`Mapper`] can be converted from and into [`Tuple`].
#[derive(Clone, Debug, PartialEq)]
pub struct Mapper(Tuple);

impl From<Tuple> for Mapper {
    fn from(t: Tuple) -> Mapper {
        Mapper(t)
    }
}

impl From<Mapper> for Tuple {
    fn from(m: Mapper) -> Tuple {
        m.0
    }
}

/// A mapped key/value pair.
///
/// Mapped range read operations on FDB return [`MappedKeyValue`].
#[derive(Clone, Debug)]
pub struct MappedKeyValue {
    key_value: KeyValue,
    range: Range,
    range_result: Vec<KeyValue>,
}

impl MappedKeyValue {
    /// Gets a reference to [`KeyValue`] from [`MappedKeyValue`].
    pub fn get_key_value_ref(&self) -> &KeyValue {
        &self.key_value
    }

    /// Gets a reference to [`Range`] from [`MappedKeyValue`].
    pub fn get_range_ref(&self) -> &Range {
        &self.range
    }

    /// Gets a reference to [`Vec<KeyValue>`] from [`MappedKeyValue`].
    pub fn get_range_result_ref(&self) -> &Vec<KeyValue> {
        &self.range_result
    }

    /// Extract [`KeyValue`] from [`MappedKeyValue`].
    pub fn into_key_value(self) -> KeyValue {
        self.key_value
    }

    /// Extract [`Range`] from [`MappedKeyValue`].
    pub fn into_range(self) -> Range {
        self.range
    }

    /// Extract [`Vec<KeyValue>`] from [`MappedKeyValue`].
    pub fn into_range_result(self) -> Vec<KeyValue> {
        self.range_result
    }

    /// Extract [`KeyValue`], [`Range`] and [`Vec<KeyValue>`] from
    /// [`MappedKeyValue`].
    pub fn into_parts(self) -> (KeyValue, Range, Vec<KeyValue>) {
        (self.key_value, self.range, self.range_result)
    }

    pub(crate) fn new(
        key_value: KeyValue,
        range: Range,
        range_result: Vec<KeyValue>,
    ) -> MappedKeyValue {
        MappedKeyValue {
            key_value,
            range,
            range_result,
        }
    }
}