-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcluster.rs
More file actions
61 lines (49 loc) · 1.5 KB
/
Copy pathcluster.rs
File metadata and controls
61 lines (49 loc) · 1.5 KB
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
use std::fmt::{
Debug,
Display,
Formatter,
};
use crate::ffi::struct_CassVersion_;
/// The version of the connected Cassandra cluster.
#[derive(Clone, Copy)]
#[repr(transparent)]
pub struct ClusterVersion(struct_CassVersion_);
impl ClusterVersion {
/// Creates a new `ClusterVersion` from the driver object.
pub(crate) fn from_driver(value: struct_CassVersion_) -> Self {
Self(value)
}
/// Returns the wrapped `struct_CassVersion_` value.
pub(crate) fn inner(&self) -> &struct_CassVersion_ {
&self.0
}
/// Returns the major version number.
pub fn major(&self) -> usize {
let n = self.inner().major_version;
usize::try_from(n).unwrap_or(0)
}
/// Returns the minor version number.
pub fn minor(&self) -> usize {
let n = self.inner().minor_version;
usize::try_from(n).unwrap_or(0)
}
/// Returns the patch version number.
pub fn patch(&self) -> usize {
let n = self.inner().patch_version;
usize::try_from(n).unwrap_or(0)
}
}
impl Debug for ClusterVersion {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
f.debug_struct("CassVersion")
.field("major", &self.major())
.field("minor", &self.minor())
.field("patch", &self.patch())
.finish()
}
}
impl Display for ClusterVersion {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
write!(f, "{}.{}.{}", self.major(), self.minor(), self.patch())
}
}