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
use arc_swap::ArcSwapOption;
use std::cmp::Ordering;
use std::hash::{Hash, Hasher};

use crate::types::CBytesShort;

#[derive(Debug)]
pub struct PreparedQuery {
    pub id: CBytesShort,
    pub query: String,
    pub keyspace: Option<String>,
    pub pk_indexes: Vec<i16>,
    pub result_metadata_id: ArcSwapOption<CBytesShort>,
}

impl Clone for PreparedQuery {
    fn clone(&self) -> Self {
        Self {
            id: self.id.clone(),
            query: self.query.clone(),
            keyspace: self.keyspace.clone(),
            pk_indexes: self.pk_indexes.clone(),
            result_metadata_id: ArcSwapOption::new(self.result_metadata_id.load().clone()),
        }
    }
}

impl PartialEq for PreparedQuery {
    #[inline]
    fn eq(&self, other: &Self) -> bool {
        self.id == other.id && *self.result_metadata_id.load() == *other.result_metadata_id.load()
    }
}

impl Eq for PreparedQuery {}

impl PartialOrd for PreparedQuery {
    #[inline]
    fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
        match self.id.partial_cmp(&other.id) {
            Some(Ordering::Equal) | None => self
                .result_metadata_id
                .load()
                .partial_cmp(&other.result_metadata_id.load()),
            result => result,
        }
    }
}

impl Ord for PreparedQuery {
    #[inline]
    fn cmp(&self, other: &Self) -> Ordering {
        match self.id.cmp(&other.id) {
            Ordering::Equal => self
                .result_metadata_id
                .load()
                .cmp(&other.result_metadata_id.load()),
            result => result,
        }
    }
}

impl Hash for PreparedQuery {
    #[inline]
    fn hash<H: Hasher>(&self, state: &mut H) {
        self.id.hash(state);
        self.result_metadata_id.load().hash(state);
    }
}