cassandra_protocol/query/
prepared_query.rs

1use arc_swap::ArcSwapOption;
2use std::cmp::Ordering;
3use std::hash::{Hash, Hasher};
4
5use crate::types::CBytesShort;
6
7#[derive(Debug)]
8pub struct PreparedQuery {
9    pub id: CBytesShort,
10    pub query: String,
11    pub keyspace: Option<String>,
12    pub pk_indexes: Vec<i16>,
13    pub result_metadata_id: ArcSwapOption<CBytesShort>,
14}
15
16impl Clone for PreparedQuery {
17    fn clone(&self) -> Self {
18        Self {
19            id: self.id.clone(),
20            query: self.query.clone(),
21            keyspace: self.keyspace.clone(),
22            pk_indexes: self.pk_indexes.clone(),
23            result_metadata_id: ArcSwapOption::new(self.result_metadata_id.load().clone()),
24        }
25    }
26}
27
28impl PartialEq for PreparedQuery {
29    #[inline]
30    fn eq(&self, other: &Self) -> bool {
31        self.id == other.id && *self.result_metadata_id.load() == *other.result_metadata_id.load()
32    }
33}
34
35impl Eq for PreparedQuery {}
36
37impl PartialOrd for PreparedQuery {
38    #[inline]
39    fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
40        Some(self.cmp(other))
41    }
42}
43
44impl Ord for PreparedQuery {
45    #[inline]
46    fn cmp(&self, other: &Self) -> Ordering {
47        match self.id.cmp(&other.id) {
48            Ordering::Equal => self
49                .result_metadata_id
50                .load()
51                .cmp(&other.result_metadata_id.load()),
52            result => result,
53        }
54    }
55}
56
57impl Hash for PreparedQuery {
58    #[inline]
59    fn hash<H: Hasher>(&self, state: &mut H) {
60        self.id.hash(state);
61        self.result_metadata_id.load().hash(state);
62    }
63}