use cassandra::util::Protected;
use cassandra_sys::CassTimestampGen as _TimestampGen;
use cassandra_sys::cass_time_from_epoch;
use cassandra_sys::cass_timestamp_gen_free;
use cassandra_sys::cass_timestamp_gen_monotonic_new;
use cassandra_sys::cass_timestamp_gen_server_side_new;
use time::Duration;
#[derive(Debug)]
pub struct TimestampGen(*mut _TimestampGen);
unsafe impl Send for TimestampGen {}
unsafe impl Sync for TimestampGen {}
impl Protected<*mut _TimestampGen> for TimestampGen {
fn inner(&self) -> *mut _TimestampGen { self.0 }
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.num_seconds())) }
}
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) } }
}