File size: 1,535 Bytes
84d2a97
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
use api::rest::ShardKeySelector;
use segment::types::ShardKey;

use crate::shards::shard::ShardId;

#[derive(Debug, Clone, PartialEq)]
pub enum ShardSelectorInternal {
    /// No shard key specified
    Empty,
    /// All apply to all keys
    All,
    /// Select one shard key
    ShardKey(ShardKey),
    /// Select multiple shard keys
    ShardKeys(Vec<ShardKey>),
    /// ShardId
    ShardId(ShardId),
}

impl ShardSelectorInternal {
    pub fn is_shard_id(&self) -> bool {
        matches!(self, ShardSelectorInternal::ShardId(_))
    }
}

impl From<Option<ShardKey>> for ShardSelectorInternal {
    fn from(key: Option<ShardKey>) -> Self {
        match key {
            None => ShardSelectorInternal::Empty,
            Some(key) => ShardSelectorInternal::ShardKey(key),
        }
    }
}

impl From<Vec<ShardKey>> for ShardSelectorInternal {
    fn from(keys: Vec<ShardKey>) -> Self {
        ShardSelectorInternal::ShardKeys(keys)
    }
}

impl From<ShardKeySelector> for ShardSelectorInternal {
    fn from(selector: ShardKeySelector) -> Self {
        match selector {
            ShardKeySelector::ShardKey(key) => ShardSelectorInternal::ShardKey(key),
            ShardKeySelector::ShardKeys(keys) => ShardSelectorInternal::ShardKeys(keys),
        }
    }
}

impl From<Option<ShardKeySelector>> for ShardSelectorInternal {
    fn from(selector: Option<ShardKeySelector>) -> Self {
        match selector {
            None => ShardSelectorInternal::Empty,
            Some(selector) => selector.into(),
        }
    }
}