discord_cassandra_cpp/cassandra/policy/
retry.rs1use crate::cassandra::util::{Protected, ProtectedInner};
2use crate::cassandra_sys::cass_retry_policy_default_new;
3use crate::cassandra_sys::cass_retry_policy_downgrading_consistency_new;
4use crate::cassandra_sys::cass_retry_policy_fallthrough_new;
5use crate::cassandra_sys::cass_retry_policy_free;
6use crate::cassandra_sys::cass_retry_policy_logging_new;
7use crate::cassandra_sys::CassRetryPolicy as _RetryPolicy;
8
9#[derive(Debug)]
11pub struct RetryPolicy(*mut _RetryPolicy);
12
13unsafe impl Send for RetryPolicy {}
16
17impl ProtectedInner<*mut _RetryPolicy> for RetryPolicy {
18 fn inner(&self) -> *mut _RetryPolicy {
19 self.0
20 }
21}
22
23impl Protected<*mut _RetryPolicy> for RetryPolicy {
24 fn build(inner: *mut _RetryPolicy) -> Self {
25 if inner.is_null() {
26 panic!("Unexpected null pointer")
27 };
28 RetryPolicy(inner)
29 }
30}
31
32impl RetryPolicy {
33 pub fn default_new() -> Self {
35 unsafe { RetryPolicy::build(cass_retry_policy_default_new()) }
36 }
37
38 pub fn downgrading_consistency_new() -> Self {
40 unsafe { RetryPolicy(cass_retry_policy_downgrading_consistency_new()) }
41 }
42
43 pub fn fallthrough_new() -> Self {
45 unsafe { RetryPolicy(cass_retry_policy_fallthrough_new()) }
46 }
47
48 pub fn logging_new(child_retry_policy: RetryPolicy) -> Self {
50 unsafe { RetryPolicy::build(cass_retry_policy_logging_new(child_retry_policy.0)) }
52 }
53}
54
55impl Drop for RetryPolicy {
56 fn drop(&mut self) {
57 unsafe {
58 cass_retry_policy_free(self.0);
59 }
60 }
61}