From 09d4df49f3e06ef636674cb937e7e8a9c9feccd9 Mon Sep 17 00:00:00 2001 From: Roman Zeyde Date: Wed, 11 Apr 2018 12:44:44 +0300 Subject: [PATCH] Move `extern crate` to main.rs --- src/daemon.rs | 6 ++---- src/main.rs | 10 +++++++--- src/store.rs | 22 ++++++++-------------- src/timer.rs | 4 +--- src/waiter.rs | 2 +- 5 files changed, 19 insertions(+), 25 deletions(-) diff --git a/src/daemon.rs b/src/daemon.rs index decddeb..3d3d645 100644 --- a/src/daemon.rs +++ b/src/daemon.rs @@ -1,12 +1,10 @@ -extern crate itertools; -extern crate reqwest; - use bitcoin::blockdata::block::BlockHeader; use bitcoin::network::encodable::ConsensusDecodable; use bitcoin::network::serialize::BitcoinHash; use bitcoin::network::serialize::RawDecoder; use bitcoin::util::hash::Sha256dHash; -use self::itertools::enumerate; +use itertools::enumerate; +use reqwest; use std::collections::{HashMap, VecDeque}; use std::io::Cursor; diff --git a/src/main.rs b/src/main.rs index f3925c6..9e03c25 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,11 +1,15 @@ -#[macro_use] -extern crate log; - extern crate bitcoin; extern crate byteorder; extern crate crypto; +extern crate itertools; +extern crate reqwest; +extern crate rocksdb; extern crate simple_logger; extern crate time; +extern crate zmq; + +#[macro_use] +extern crate log; mod daemon; mod store; diff --git a/src/store.rs b/src/store.rs index 4ac936a..076bf44 100644 --- a/src/store.rs +++ b/src/store.rs @@ -1,20 +1,14 @@ -extern crate bitcoin; -extern crate byteorder; -extern crate crypto; -extern crate rocksdb; -extern crate time; - -use self::rocksdb::{DBCompactionStyle, DBCompressionType, WriteBatch, WriteOptions, DB}; use bitcoin::blockdata::block::BlockHeader; use bitcoin::network::serialize::deserialize; +use rocksdb; use std::char::from_digit; use std::collections::HashMap; -use self::time::{Duration, PreciseTime}; +use time::{Duration, PreciseTime}; use Bytes; pub struct Store { - db: DB, + db: rocksdb::DB, rows: Vec, start: PreciseTime, } @@ -42,10 +36,10 @@ impl Store { pub fn open(path: &str, opts: StoreOptions) -> Store { let mut db_opts = rocksdb::Options::default(); db_opts.create_if_missing(true); - db_opts.set_compaction_style(DBCompactionStyle::Level); + db_opts.set_compaction_style(rocksdb::DBCompactionStyle::Level); db_opts.set_max_open_files(256); db_opts.set_use_fsync(false); - db_opts.set_compression_type(DBCompressionType::Snappy); + db_opts.set_compression_type(rocksdb::DBCompressionType::Snappy); db_opts.set_target_file_size_base(128 << 20); db_opts.set_write_buffer_size(256 << 20); // db_opts.set_compaction_readahead_size(2 << 20); @@ -55,7 +49,7 @@ impl Store { block_opts.set_block_size(256 << 10); info!("opening {}", path); Store { - db: DB::open(&db_opts, &path).unwrap(), + db: rocksdb::DB::open(&db_opts, &path).unwrap(), rows: vec![], start: PreciseTime::now(), } @@ -71,11 +65,11 @@ impl Store { } pub fn flush(&mut self) { - let mut batch = WriteBatch::default(); + let mut batch = rocksdb::WriteBatch::default(); for row in &self.rows { batch.put(row.key.as_slice(), row.value.as_slice()).unwrap(); } - let mut opts = WriteOptions::new(); + let mut opts = rocksdb::WriteOptions::new(); opts.set_sync(true); self.db.write_opt(batch, &opts).unwrap(); self.rows.clear(); diff --git a/src/timer.rs b/src/timer.rs index b5443ac..dccf30c 100644 --- a/src/timer.rs +++ b/src/timer.rs @@ -1,8 +1,6 @@ -extern crate time; - use std::fmt::Write; use std::collections::HashMap; -use self::time::{Duration, PreciseTime}; +use time::{Duration, PreciseTime}; pub struct Timer { durations: HashMap, diff --git a/src/waiter.rs b/src/waiter.rs index 2d81f9c..4ea1b04 100644 --- a/src/waiter.rs +++ b/src/waiter.rs @@ -1,4 +1,4 @@ -extern crate zmq; +use zmq; use Bytes;