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
use crate::ffi;
use crate::{checkpoint::Checkpoint, handle::Handle, Error};
use std::marker::PhantomData;

pub trait CreateCheckpointObject {
    unsafe fn create_checkpoint_object_raw(&self) -> Result<*mut ffi::rocksdb_checkpoint_t, Error>;
    fn create_checkpoint_object(&self) -> Result<Checkpoint<'_>, Error> {
        let checkpoint: *mut ffi::rocksdb_checkpoint_t;

        unsafe { checkpoint = self.create_checkpoint_object_raw()? };

        if checkpoint.is_null() {
            return Err(Error::new("Could not create checkpoint object.".to_owned()));
        }

        Ok(Checkpoint {
            inner: checkpoint,
            _db: PhantomData,
        })
    }
}

impl<T> CreateCheckpointObject for T
where
    T: Handle<ffi::rocksdb_t>,
{
    unsafe fn create_checkpoint_object_raw(&self) -> Result<*mut ffi::rocksdb_checkpoint_t, Error> {
        Ok(ffi_try!(ffi::rocksdb_checkpoint_object_create(
            self.handle(),
        )))
    }
}