Use `Self` where possible (#538)

master
adamnemecek 3 years ago committed by GitHub
parent 81a9edea83
commit 32fbd92444
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 15
      src/backup.rs
  2. 4
      src/checkpoint.rs
  3. 2
      src/column_family.rs
  4. 2
      src/compaction_filter_factory.rs
  5. 8
      src/db_iterator.rs
  6. 48
      src/db_options.rs
  7. 4
      src/db_pinnable_slice.rs
  8. 4
      src/perf.rs
  9. 10
      src/sst_file_writer.rs
  10. 4
      src/write_batch.rs

@ -48,10 +48,7 @@ pub struct RestoreOptions {
impl BackupEngine { impl BackupEngine {
/// Open a backup engine with the specified options. /// Open a backup engine with the specified options.
pub fn open<P: AsRef<Path>>( pub fn open<P: AsRef<Path>>(opts: &BackupEngineOptions, path: P) -> Result<Self, Error> {
opts: &BackupEngineOptions,
path: P,
) -> Result<BackupEngine, Error> {
let path = path.as_ref(); let path = path.as_ref();
let cpath = if let Ok(e) = CString::new(path.to_string_lossy().as_bytes()) { let cpath = if let Ok(e) = CString::new(path.to_string_lossy().as_bytes()) {
e e
@ -70,7 +67,7 @@ impl BackupEngine {
return Err(Error::new("Could not initialize backup engine.".to_owned())); 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. /// Captures the state of the database in the latest backup.
@ -231,25 +228,25 @@ impl RestoreOptions {
} }
impl Default for BackupEngineOptions { impl Default for BackupEngineOptions {
fn default() -> BackupEngineOptions { fn default() -> Self {
unsafe { unsafe {
let opts = ffi::rocksdb_options_create(); let opts = ffi::rocksdb_options_create();
if opts.is_null() { if opts.is_null() {
panic!("Could not create RocksDB backup options"); panic!("Could not create RocksDB backup options");
} }
BackupEngineOptions { inner: opts } Self { inner: opts }
} }
} }
} }
impl Default for RestoreOptions { impl Default for RestoreOptions {
fn default() -> RestoreOptions { fn default() -> Self {
unsafe { unsafe {
let opts = ffi::rocksdb_restore_options_create(); let opts = ffi::rocksdb_restore_options_create();
if opts.is_null() { if opts.is_null() {
panic!("Could not create RocksDB restore options"); panic!("Could not create RocksDB restore options");
} }
RestoreOptions { inner: opts } Self { inner: opts }
} }
} }
} }

@ -37,7 +37,7 @@ impl<'db> Checkpoint<'db> {
/// ///
/// Does not actually produce checkpoints, call `.create_checkpoint()` method to produce /// Does not actually produce checkpoints, call `.create_checkpoint()` method to produce
/// a DB checkpoint. /// a DB checkpoint.
pub fn new(db: &'db DB) -> Result<Checkpoint<'db>, Error> { pub fn new(db: &'db DB) -> Result<Self, Error> {
let checkpoint: *mut ffi::rocksdb_checkpoint_t; let checkpoint: *mut ffi::rocksdb_checkpoint_t;
unsafe { checkpoint = ffi_try!(ffi::rocksdb_checkpoint_object_create(db.inner)) }; 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())); return Err(Error::new("Could not create checkpoint object.".to_owned()));
} }
Ok(Checkpoint { Ok(Self {
inner: checkpoint, inner: checkpoint,
_db: PhantomData, _db: PhantomData,
}) })

@ -34,7 +34,7 @@ impl ColumnFamilyDescriptor {
where where
S: Into<String>, S: Into<String>,
{ {
ColumnFamilyDescriptor { Self {
name: name.into(), name: name.into(),
options, options,
} }

@ -56,7 +56,7 @@ impl CompactionFilterContext {
let is_manual_compaction = let is_manual_compaction =
ffi::rocksdb_compactionfiltercontext_is_manual_compaction(ptr) != 0; ffi::rocksdb_compactionfiltercontext_is_manual_compaction(ptr) != 0;
CompactionFilterContext { Self {
is_full_compaction, is_full_compaction,
is_manual_compaction, is_manual_compaction,
} }

@ -81,9 +81,9 @@ pub struct DBRawIteratorWithThreadMode<'a, D: DBAccess> {
} }
impl<'a, D: DBAccess> DBRawIteratorWithThreadMode<'a, D> { 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 { unsafe {
DBRawIteratorWithThreadMode { Self {
inner: ffi::rocksdb_create_iterator(db.inner(), readopts.inner), inner: ffi::rocksdb_create_iterator(db.inner(), readopts.inner),
_readopts: readopts, _readopts: readopts,
db: PhantomData, db: PhantomData,
@ -95,9 +95,9 @@ impl<'a, D: DBAccess> DBRawIteratorWithThreadMode<'a, D> {
db: &'a D, db: &'a D,
cf_handle: *mut ffi::rocksdb_column_family_handle_t, cf_handle: *mut ffi::rocksdb_column_family_handle_t,
readopts: ReadOptions, readopts: ReadOptions,
) -> DBRawIteratorWithThreadMode<'a, D> { ) -> Self {
unsafe { unsafe {
DBRawIteratorWithThreadMode { Self {
inner: ffi::rocksdb_create_iterator_cf(db.inner(), readopts.inner, cf_handle), inner: ffi::rocksdb_create_iterator_cf(db.inner(), readopts.inner, cf_handle),
_readopts: readopts, _readopts: readopts,
db: PhantomData, db: PhantomData,

@ -107,23 +107,23 @@ impl Drop for EnvWrapper {
impl Env { impl Env {
/// Returns default env /// Returns default env
pub fn default() -> Result<Env, Error> { pub fn default() -> Result<Self, Error> {
let env = unsafe { ffi::rocksdb_create_default_env() }; let env = unsafe { ffi::rocksdb_create_default_env() };
if env.is_null() { if env.is_null() {
Err(Error::new("Could not create mem env".to_owned())) Err(Error::new("Could not create mem env".to_owned()))
} else { } 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 /// Returns a new environment that stores its data in memory and delegates
/// all non-file-storage tasks to base_env. /// all non-file-storage tasks to base_env.
pub fn mem_env() -> Result<Env, Error> { pub fn mem_env() -> Result<Self, Error> {
let env = unsafe { ffi::rocksdb_create_mem_env() }; let env = unsafe { ffi::rocksdb_create_mem_env() };
if env.is_null() { if env.is_null() {
Err(Error::new("Could not create mem env".to_owned())) Err(Error::new("Could not create mem env".to_owned()))
} else { } 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 { impl Default for BlockBasedOptions {
fn default() -> BlockBasedOptions { fn default() -> Self {
let block_opts = unsafe { ffi::rocksdb_block_based_options_create() }; let block_opts = unsafe { ffi::rocksdb_block_based_options_create() };
if block_opts.is_null() { if block_opts.is_null() {
panic!("Could not create RocksDB block based options"); panic!("Could not create RocksDB block based options");
} }
BlockBasedOptions { Self {
inner: block_opts, inner: block_opts,
outlive: BlockBasedOptionsMustOutliveDB::default(), outlive: BlockBasedOptionsMustOutliveDB::default(),
} }
@ -762,12 +762,12 @@ impl CuckooTableOptions {
} }
impl Default for CuckooTableOptions { impl Default for CuckooTableOptions {
fn default() -> CuckooTableOptions { fn default() -> Self {
let opts = unsafe { ffi::rocksdb_cuckoo_options_create() }; let opts = unsafe { ffi::rocksdb_cuckoo_options_create() };
if opts.is_null() { if opts.is_null() {
panic!("Could not create RocksDB cuckoo options"); panic!("Could not create RocksDB cuckoo options");
} }
CuckooTableOptions { inner: opts } Self { inner: opts }
} }
} }
@ -2865,13 +2865,13 @@ impl Options {
} }
impl Default for Options { impl Default for Options {
fn default() -> Options { fn default() -> Self {
unsafe { unsafe {
let opts = ffi::rocksdb_options_create(); let opts = ffi::rocksdb_options_create();
if opts.is_null() { if opts.is_null() {
panic!("Could not create RocksDB options"); panic!("Could not create RocksDB options");
} }
Options { Self {
inner: opts, inner: opts,
outlive: OptionsMustOutliveDB::default(), outlive: OptionsMustOutliveDB::default(),
} }
@ -2904,12 +2904,12 @@ impl FlushOptions {
} }
impl Default for FlushOptions { impl Default for FlushOptions {
fn default() -> FlushOptions { fn default() -> Self {
let flush_opts = unsafe { ffi::rocksdb_flushoptions_create() }; let flush_opts = unsafe { ffi::rocksdb_flushoptions_create() };
if flush_opts.is_null() { if flush_opts.is_null() {
panic!("Could not create RocksDB flush options"); 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 { impl Default for WriteOptions {
fn default() -> WriteOptions { fn default() -> Self {
let write_opts = unsafe { ffi::rocksdb_writeoptions_create() }; let write_opts = unsafe { ffi::rocksdb_writeoptions_create() };
if write_opts.is_null() { if write_opts.is_null() {
panic!("Could not create RocksDB write options"); 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 { impl Default for ReadOptions {
fn default() -> ReadOptions { fn default() -> Self {
unsafe { unsafe {
ReadOptions { Self {
inner: ffi::rocksdb_readoptions_create(), inner: ffi::rocksdb_readoptions_create(),
iterate_upper_bound: None, iterate_upper_bound: None,
iterate_lower_bound: None, iterate_lower_bound: None,
@ -3255,9 +3255,9 @@ impl IngestExternalFileOptions {
} }
impl Default for IngestExternalFileOptions { impl Default for IngestExternalFileOptions {
fn default() -> IngestExternalFileOptions { fn default() -> Self {
unsafe { unsafe {
IngestExternalFileOptions { Self {
inner: ffi::rocksdb_ingestexternalfileoptions_create(), inner: ffi::rocksdb_ingestexternalfileoptions_create(),
} }
} }
@ -3362,12 +3362,12 @@ pub struct FifoCompactOptions {
} }
impl Default for FifoCompactOptions { impl Default for FifoCompactOptions {
fn default() -> FifoCompactOptions { fn default() -> Self {
let opts = unsafe { ffi::rocksdb_fifo_compaction_options_create() }; let opts = unsafe { ffi::rocksdb_fifo_compaction_options_create() };
if opts.is_null() { if opts.is_null() {
panic!("Could not create RocksDB Fifo Compaction Options"); 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 { impl Default for UniversalCompactOptions {
fn default() -> UniversalCompactOptions { fn default() -> Self {
let opts = unsafe { ffi::rocksdb_universal_compaction_options_create() }; let opts = unsafe { ffi::rocksdb_universal_compaction_options_create() };
if opts.is_null() { if opts.is_null() {
panic!("Could not create RocksDB Universal Compaction Options"); 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 { impl Default for CompactOptions {
fn default() -> CompactOptions { fn default() -> Self {
let opts = unsafe { ffi::rocksdb_compactoptions_create() }; let opts = unsafe { ffi::rocksdb_compactoptions_create() };
if opts.is_null() { if opts.is_null() {
panic!("Could not create RocksDB Compact Options"); panic!("Could not create RocksDB Compact Options");
} }
CompactOptions { inner: opts } Self { inner: opts }
} }
} }

@ -63,8 +63,8 @@ impl<'a> DBPinnableSlice<'a> {
/// ///
/// # Unsafe /// # Unsafe
/// Requires that the pointer must be generated by rocksdb_get_pinned /// 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> { pub(crate) unsafe fn from_c(ptr: *mut ffi::rocksdb_pinnableslice_t) -> Self {
DBPinnableSlice { Self {
ptr, ptr,
db: PhantomData, db: PhantomData,
} }

@ -125,12 +125,12 @@ pub struct PerfContext {
} }
impl Default for PerfContext { impl Default for PerfContext {
fn default() -> PerfContext { fn default() -> Self {
let ctx = unsafe { ffi::rocksdb_perfcontext_create() }; let ctx = unsafe { ffi::rocksdb_perfcontext_create() };
if ctx.is_null() { if ctx.is_null() {
panic!("Could not create Perf Context"); panic!("Could not create Perf Context");
} }
PerfContext { inner: ctx } Self { inner: ctx }
} }
} }

@ -43,20 +43,20 @@ impl Drop for EnvOptions {
} }
impl Default for EnvOptions { impl Default for EnvOptions {
fn default() -> EnvOptions { fn default() -> Self {
let opts = unsafe { ffi::rocksdb_envoptions_create() }; let opts = unsafe { ffi::rocksdb_envoptions_create() };
EnvOptions { inner: opts } Self { inner: opts }
} }
} }
impl<'a> SstFileWriter<'a> { impl<'a> SstFileWriter<'a> {
/// Initializes SstFileWriter with given DB options. /// 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 env_options = EnvOptions::default();
let writer = SstFileWriter::create_raw(opts, &env_options); let writer = Self::create_raw(opts, &env_options);
SstFileWriter { Self {
inner: writer, inner: writer,
phantom: PhantomData, phantom: PhantomData,
} }

@ -267,8 +267,8 @@ impl WriteBatch {
} }
impl Default for WriteBatch { impl Default for WriteBatch {
fn default() -> WriteBatch { fn default() -> Self {
WriteBatch { Self {
inner: unsafe { ffi::rocksdb_writebatch_create() }, inner: unsafe { ffi::rocksdb_writebatch_create() },
} }
} }

Loading…
Cancel
Save