use crate::cassandra::util::{Protected, ProtectedInner};
use crate::cassandra_sys::cass_time_from_epoch;
use crate::cassandra_sys::cass_timestamp_gen_free;
use crate::cassandra_sys::cass_timestamp_gen_monotonic_new;
use crate::cassandra_sys::cass_timestamp_gen_server_side_new;
use crate::cassandra_sys::CassTimestampGen as _TimestampGen;
use std::time::Duration;
#[derive(Debug)]
pub struct TimestampGen(*mut _TimestampGen);
unsafe impl Send for TimestampGen {}
unsafe impl Sync for TimestampGen {}
impl ProtectedInner<*mut _TimestampGen> for TimestampGen {
fn inner(&self) -> *mut _TimestampGen {
self.0
}
}
impl Protected<*mut _TimestampGen> for TimestampGen {
fn build(inner: *mut _TimestampGen) -> Self {
if inner.is_null() {
panic!("Unexpected null pointer")
};
TimestampGen(inner)
}
}
#[derive(Debug)]
pub struct Time(i64);
impl TimestampGen {
pub fn time_from_epoch(epoch_seconds: Duration) -> Time {
unsafe { Time(cass_time_from_epoch(epoch_seconds.as_secs() as _)) }
}
pub fn gen_monotonic_new() -> Self {
unsafe { TimestampGen(cass_timestamp_gen_monotonic_new()) }
}
pub fn gen_server_side_new() -> Self {
unsafe { TimestampGen(cass_timestamp_gen_server_side_new()) }
}
}
impl Drop for TimestampGen {
fn drop(&mut self) {
unsafe { cass_timestamp_gen_free(self.0) }
}
}