diff --git a/src/backup.rs b/src/backup.rs index f079042..f6fb733 100644 --- a/src/backup.rs +++ b/src/backup.rs @@ -48,10 +48,7 @@ pub struct RestoreOptions { impl BackupEngine { /// Open a backup engine with the specified options. - pub fn open>( - opts: &BackupEngineOptions, - path: P, - ) -> Result { + pub fn open>(opts: &BackupEngineOptions, path: P) -> Result { let path = path.as_ref(); let cpath = if let Ok(e) = CString::new(path.to_string_lossy().as_bytes()) { e @@ -70,7 +67,7 @@ impl BackupEngine { return Err(Error::new("Could not initialize backup engine.".to_owned())); } - Ok(BackupEngine { inner: be }) + Ok(Self { inner: be }) } /// Captures the state of the database in the latest backup. @@ -231,25 +228,25 @@ impl RestoreOptions { } impl Default for BackupEngineOptions { - fn default() -> BackupEngineOptions { + fn default() -> Self { unsafe { let opts = ffi::rocksdb_options_create(); if opts.is_null() { panic!("Could not create RocksDB backup options"); } - BackupEngineOptions { inner: opts } + Self { inner: opts } } } } impl Default for RestoreOptions { - fn default() -> RestoreOptions { + fn default() -> Self { unsafe { let opts = ffi::rocksdb_restore_options_create(); if opts.is_null() { panic!("Could not create RocksDB restore options"); } - RestoreOptions { inner: opts } + Self { inner: opts } } } } diff --git a/src/checkpoint.rs b/src/checkpoint.rs index 19f2313..ff2a640 100644 --- a/src/checkpoint.rs +++ b/src/checkpoint.rs @@ -37,7 +37,7 @@ impl<'db> Checkpoint<'db> { /// /// Does not actually produce checkpoints, call `.create_checkpoint()` method to produce /// a DB checkpoint. - pub fn new(db: &'db DB) -> Result, Error> { + pub fn new(db: &'db DB) -> Result { let checkpoint: *mut ffi::rocksdb_checkpoint_t; unsafe { checkpoint = ffi_try!(ffi::rocksdb_checkpoint_object_create(db.inner)) }; @@ -46,7 +46,7 @@ impl<'db> Checkpoint<'db> { return Err(Error::new("Could not create checkpoint object.".to_owned())); } - Ok(Checkpoint { + Ok(Self { inner: checkpoint, _db: PhantomData, }) diff --git a/src/column_family.rs b/src/column_family.rs index 1967f7d..c82d5c1 100644 --- a/src/column_family.rs +++ b/src/column_family.rs @@ -34,7 +34,7 @@ impl ColumnFamilyDescriptor { where S: Into, { - ColumnFamilyDescriptor { + Self { name: name.into(), options, } diff --git a/src/compaction_filter_factory.rs b/src/compaction_filter_factory.rs index e739f24..1e3159c 100644 --- a/src/compaction_filter_factory.rs +++ b/src/compaction_filter_factory.rs @@ -56,7 +56,7 @@ impl CompactionFilterContext { let is_manual_compaction = ffi::rocksdb_compactionfiltercontext_is_manual_compaction(ptr) != 0; - CompactionFilterContext { + Self { is_full_compaction, is_manual_compaction, } diff --git a/src/db_iterator.rs b/src/db_iterator.rs index 2a958c8..5027aeb 100644 --- a/src/db_iterator.rs +++ b/src/db_iterator.rs @@ -81,9 +81,9 @@ pub struct DBRawIteratorWithThreadMode<'a, D: DBAccess> { } impl<'a, D: DBAccess> DBRawIteratorWithThreadMode<'a, D> { - pub(crate) fn new(db: &D, readopts: ReadOptions) -> DBRawIteratorWithThreadMode<'a, D> { + pub(crate) fn new(db: &D, readopts: ReadOptions) -> Self { unsafe { - DBRawIteratorWithThreadMode { + Self { inner: ffi::rocksdb_create_iterator(db.inner(), readopts.inner), _readopts: readopts, db: PhantomData, @@ -95,9 +95,9 @@ impl<'a, D: DBAccess> DBRawIteratorWithThreadMode<'a, D> { db: &'a D, cf_handle: *mut ffi::rocksdb_column_family_handle_t, readopts: ReadOptions, - ) -> DBRawIteratorWithThreadMode<'a, D> { + ) -> Self { unsafe { - DBRawIteratorWithThreadMode { + Self { inner: ffi::rocksdb_create_iterator_cf(db.inner(), readopts.inner, cf_handle), _readopts: readopts, db: PhantomData, diff --git a/src/db_options.rs b/src/db_options.rs index 8b0c568..899817f 100644 --- a/src/db_options.rs +++ b/src/db_options.rs @@ -107,23 +107,23 @@ impl Drop for EnvWrapper { impl Env { /// Returns default env - pub fn default() -> Result { + pub fn default() -> Result { let env = unsafe { ffi::rocksdb_create_default_env() }; if env.is_null() { Err(Error::new("Could not create mem env".to_owned())) } else { - Ok(Env(Arc::new(EnvWrapper { inner: env }))) + Ok(Self(Arc::new(EnvWrapper { inner: env }))) } } /// Returns a new environment that stores its data in memory and delegates /// all non-file-storage tasks to base_env. - pub fn mem_env() -> Result { + pub fn mem_env() -> Result { let env = unsafe { ffi::rocksdb_create_mem_env() }; if env.is_null() { Err(Error::new("Could not create mem env".to_owned())) } else { - Ok(Env(Arc::new(EnvWrapper { inner: env }))) + Ok(Self(Arc::new(EnvWrapper { inner: env }))) } } @@ -700,12 +700,12 @@ impl BlockBasedOptions { } impl Default for BlockBasedOptions { - fn default() -> BlockBasedOptions { + fn default() -> Self { let block_opts = unsafe { ffi::rocksdb_block_based_options_create() }; if block_opts.is_null() { panic!("Could not create RocksDB block based options"); } - BlockBasedOptions { + Self { inner: block_opts, outlive: BlockBasedOptionsMustOutliveDB::default(), } @@ -762,12 +762,12 @@ impl CuckooTableOptions { } impl Default for CuckooTableOptions { - fn default() -> CuckooTableOptions { + fn default() -> Self { let opts = unsafe { ffi::rocksdb_cuckoo_options_create() }; if opts.is_null() { panic!("Could not create RocksDB cuckoo options"); } - CuckooTableOptions { inner: opts } + Self { inner: opts } } } @@ -2865,13 +2865,13 @@ impl Options { } impl Default for Options { - fn default() -> Options { + fn default() -> Self { unsafe { let opts = ffi::rocksdb_options_create(); if opts.is_null() { panic!("Could not create RocksDB options"); } - Options { + Self { inner: opts, outlive: OptionsMustOutliveDB::default(), } @@ -2904,12 +2904,12 @@ impl FlushOptions { } impl Default for FlushOptions { - fn default() -> FlushOptions { + fn default() -> Self { let flush_opts = unsafe { ffi::rocksdb_flushoptions_create() }; if flush_opts.is_null() { panic!("Could not create RocksDB flush options"); } - FlushOptions { inner: flush_opts } + Self { inner: flush_opts } } } @@ -2992,12 +2992,12 @@ impl WriteOptions { } impl Default for WriteOptions { - fn default() -> WriteOptions { + fn default() -> Self { let write_opts = unsafe { ffi::rocksdb_writeoptions_create() }; if write_opts.is_null() { panic!("Could not create RocksDB write options"); } - WriteOptions { inner: write_opts } + Self { inner: write_opts } } } @@ -3191,9 +3191,9 @@ impl ReadOptions { } impl Default for ReadOptions { - fn default() -> ReadOptions { + fn default() -> Self { unsafe { - ReadOptions { + Self { inner: ffi::rocksdb_readoptions_create(), iterate_upper_bound: None, iterate_lower_bound: None, @@ -3255,9 +3255,9 @@ impl IngestExternalFileOptions { } impl Default for IngestExternalFileOptions { - fn default() -> IngestExternalFileOptions { + fn default() -> Self { unsafe { - IngestExternalFileOptions { + Self { inner: ffi::rocksdb_ingestexternalfileoptions_create(), } } @@ -3362,12 +3362,12 @@ pub struct FifoCompactOptions { } impl Default for FifoCompactOptions { - fn default() -> FifoCompactOptions { + fn default() -> Self { let opts = unsafe { ffi::rocksdb_fifo_compaction_options_create() }; if opts.is_null() { panic!("Could not create RocksDB Fifo Compaction Options"); } - FifoCompactOptions { inner: opts } + Self { inner: opts } } } @@ -3404,12 +3404,12 @@ pub struct UniversalCompactOptions { } impl Default for UniversalCompactOptions { - fn default() -> UniversalCompactOptions { + fn default() -> Self { let opts = unsafe { ffi::rocksdb_universal_compaction_options_create() }; if opts.is_null() { panic!("Could not create RocksDB Universal Compaction Options"); } - UniversalCompactOptions { inner: opts } + Self { inner: opts } } } @@ -3526,12 +3526,12 @@ pub struct CompactOptions { } impl Default for CompactOptions { - fn default() -> CompactOptions { + fn default() -> Self { let opts = unsafe { ffi::rocksdb_compactoptions_create() }; if opts.is_null() { panic!("Could not create RocksDB Compact Options"); } - CompactOptions { inner: opts } + Self { inner: opts } } } diff --git a/src/db_pinnable_slice.rs b/src/db_pinnable_slice.rs index 465af1e..410daa4 100644 --- a/src/db_pinnable_slice.rs +++ b/src/db_pinnable_slice.rs @@ -63,8 +63,8 @@ impl<'a> DBPinnableSlice<'a> { /// /// # Unsafe /// Requires that the pointer must be generated by rocksdb_get_pinned - pub(crate) unsafe fn from_c(ptr: *mut ffi::rocksdb_pinnableslice_t) -> DBPinnableSlice<'a> { - DBPinnableSlice { + pub(crate) unsafe fn from_c(ptr: *mut ffi::rocksdb_pinnableslice_t) -> Self { + Self { ptr, db: PhantomData, } diff --git a/src/perf.rs b/src/perf.rs index d099a89..a44b671 100644 --- a/src/perf.rs +++ b/src/perf.rs @@ -125,12 +125,12 @@ pub struct PerfContext { } impl Default for PerfContext { - fn default() -> PerfContext { + fn default() -> Self { let ctx = unsafe { ffi::rocksdb_perfcontext_create() }; if ctx.is_null() { panic!("Could not create Perf Context"); } - PerfContext { inner: ctx } + Self { inner: ctx } } } diff --git a/src/sst_file_writer.rs b/src/sst_file_writer.rs index 0678c9d..2aa84b5 100644 --- a/src/sst_file_writer.rs +++ b/src/sst_file_writer.rs @@ -43,20 +43,20 @@ impl Drop for EnvOptions { } impl Default for EnvOptions { - fn default() -> EnvOptions { + fn default() -> Self { let opts = unsafe { ffi::rocksdb_envoptions_create() }; - EnvOptions { inner: opts } + Self { inner: opts } } } impl<'a> SstFileWriter<'a> { /// Initializes SstFileWriter with given DB options. - pub fn create(opts: &'a Options) -> SstFileWriter { + pub fn create(opts: &'a Options) -> Self { let env_options = EnvOptions::default(); - let writer = SstFileWriter::create_raw(opts, &env_options); + let writer = Self::create_raw(opts, &env_options); - SstFileWriter { + Self { inner: writer, phantom: PhantomData, } diff --git a/src/write_batch.rs b/src/write_batch.rs index 00707f9..8e09709 100644 --- a/src/write_batch.rs +++ b/src/write_batch.rs @@ -267,8 +267,8 @@ impl WriteBatch { } impl Default for WriteBatch { - fn default() -> WriteBatch { - WriteBatch { + fn default() -> Self { + Self { inner: unsafe { ffi::rocksdb_writebatch_create() }, } }