Skip to content

Commit 5a801fb

Browse files
committed
Updated serde to version 0.9 and log4rs to version 0.6 and added a root Cargo.toml with workspace configuration
1 parent cb808df commit 5a801fb

File tree

19 files changed

+53
-49
lines changed

19 files changed

+53
-49
lines changed

Cargo.toml

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
[workspace]
2+
members = [
3+
"exar-core",
4+
"exar-testkit",
5+
"exar-net",
6+
"exar-client",
7+
"exar-server",
8+
"exar-db"
9+
]
10+
11+
[profile.release]
12+
debug = true
13+
opt-level = 3

exar-client/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
extern crate exar;
5656
extern crate exar_net;
5757

58-
#[cfg(test)] #[macro_use]
58+
#[cfg(test)]
5959
extern crate exar_testkit;
6060

6161
#[macro_use]

exar-core/Cargo.toml

+4-4
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@ log = "0.3"
1515
rand = "0.3"
1616
time = "0.1"
1717
rustc-serialize = { optional = true, version = "0.3" }
18-
serde = { optional = true, version = "0.7" }
19-
serde_macros = { optional = true, version = "0.7" }
18+
serde = { optional = true, version = "0.9" }
19+
serde_derive = { optional = true, version = "0.9" }
2020

2121
[features]
2222
rustc-serialization = ["rustc-serialize"]
23-
serde-serialization = ["serde", "serde_macros"]
23+
serde-serialization = ["serde", "serde_derive"]
2424

2525
[dev-dependencies]
2626
exar-testkit = { version = "0.1", path = "../exar-testkit" }
27-
serde_json = "0.7"
27+
serde_json = "0.9"

exar-core/benches/database.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ extern crate exar;
44
extern crate rand;
55
extern crate test;
66

7-
#[cfg(test)] #[macro_use]
7+
#[cfg(test)]
88
extern crate exar_testkit;
99

1010
use exar::*;
@@ -13,7 +13,7 @@ use test::Bencher;
1313

1414
#[bench]
1515
fn bench_publish(b: &mut Bencher) {
16-
let ref collection_name = random_collection_name();
16+
let collection_name = &random_collection_name();
1717
let config = DatabaseConfig::default();
1818
let mut db = Database::new(config);
1919
let connection = db.connect(collection_name).unwrap();

exar-core/src/collection.rs

+2-5
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use rand::Rng;
66
use std::sync::mpsc::channel;
77

88
/// Exar DB's collection of events, containing the reference to the log and index files.
9-
///
9+
///
1010
/// It is responsible of creating and managing the log scanner threads and the single-threaded logger.
1111
/// It allows publishing and subscribing to the underling events log.
1212
///
@@ -112,10 +112,7 @@ impl Collection {
112112
None => Err(DatabaseError::SubscriptionError)
113113
},
114114
RoutingStrategy::RoundRobin(ref last_index) => {
115-
let mut new_index = 0;
116-
if last_index + 1 < self.scanners.len() {
117-
new_index = last_index + 1;
118-
}
115+
let new_index = if last_index + 1 < self.scanners.len() { last_index + 1 } else { 0 };
119116
match self.scanners.get(new_index) {
120117
Some(scanner) => scanner.handle_subscription(subscription).and_then(|_| {
121118
Ok(RoutingStrategy::RoundRobin(new_index))

exar-core/src/config.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@ impl DatabaseConfig {
6161
Some(collection_config) => {
6262
let config = collection_config.clone();
6363
CollectionConfig {
64-
logs_path: config.logs_path.unwrap_or(self.logs_path.clone()),
65-
index_granularity: config.index_granularity.unwrap_or(self.index_granularity.clone()),
64+
logs_path: config.logs_path.unwrap_or_else(|| self.logs_path.clone()),
65+
index_granularity: config.index_granularity.unwrap_or_else(|| self.index_granularity),
6666
scanners: match config.scanners {
6767
Some(scanners_config) => ScannersConfig {
6868
nr_of_scanners: scanners_config.nr_of_scanners.unwrap_or(self.scanners.nr_of_scanners),
@@ -73,7 +73,7 @@ impl DatabaseConfig {
7373
sleep_time_in_ms: self.scanners.sleep_time_in_ms
7474
}
7575
},
76-
routing_strategy: config.routing_strategy.unwrap_or(self.routing_strategy.clone())
76+
routing_strategy: config.routing_strategy.unwrap_or_else(|| self.routing_strategy.clone())
7777
}
7878
},
7979
None => CollectionConfig {

exar-core/src/error.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,9 @@ impl ToTabSeparatedString for DatabaseError {
4343
DatabaseError::IoError(ref error_kind, ref description) => {
4444
tab_separated!("IoError", error_kind.to_tab_separated_string(), description)
4545
},
46-
DatabaseError::ParseError(ref error) => match error {
47-
&ParseError::ParseError(ref description) => tab_separated!("ParseError", "ParseError", description),
48-
&ParseError::MissingField(index) => tab_separated!("ParseError", "MissingField", index)
46+
DatabaseError::ParseError(ref error) => match *error {
47+
ParseError::ParseError(ref description) => tab_separated!("ParseError", "ParseError", description),
48+
ParseError::MissingField(index) => tab_separated!("ParseError", "MissingField", index)
4949
},
5050
DatabaseError::SubscriptionError => tab_separated!("SubscriptionError"),
5151
DatabaseError::ValidationError(ref error) => tab_separated!("ValidationError", error.description)

exar-core/src/event.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ impl FromTabSeparatedStr for Event {
8080
let timestamp = try!(parser.parse_next());
8181
let tags: String = try!(parser.parse_next());
8282
let data: String = try!(parser.parse_next());
83-
let tags: Vec<_> = tags.split(" ").map(|x| x.to_owned()).collect();
83+
let tags: Vec<_> = tags.split(' ').map(|x| x.to_owned()).collect();
8484
Ok(Event {
8585
id: id,
8686
tags: tags,
@@ -138,8 +138,7 @@ impl EventStream {
138138
pub fn recv(&self) -> Result<Event, EventStreamError> {
139139
match self.event_stream_receiver.recv() {
140140
Ok(EventStreamMessage::Event(event)) => Ok(event),
141-
Ok(EventStreamMessage::End) => Err(EventStreamError::Closed),
142-
Err(_) => Err(EventStreamError::Closed)
141+
Ok(EventStreamMessage::End) | Err(_) => Err(EventStreamError::Closed)
143142
}
144143
}
145144
/// Attempts to return a pending event on this event stream without blocking.

exar-core/src/lib.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
#![cfg_attr(feature = "serde-serialization", feature(custom_derive, plugin))]
2-
#![cfg_attr(feature = "serde-serialization", plugin(serde_macros))]
3-
41
//! # Exar DB
52
//! Exar DB is an event store with streaming support
63
//! which uses a flat-file for each collection of events
@@ -58,6 +55,7 @@
5855
5956
#[cfg(feature = "rustc-serialization")] extern crate rustc_serialize;
6057
#[cfg(feature = "serde-serialization")] extern crate serde;
58+
#[cfg(feature = "serde-serialization")] #[macro_use] extern crate serde_derive;
6159

6260
#[cfg(test)] #[macro_use]
6361
extern crate exar_testkit;

exar-core/src/log.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,7 @@ impl Log {
9191
pub fn remove(&self) -> Result<(), DatabaseError> {
9292
match remove_file(self.get_path()) {
9393
Ok(()) => match remove_file(self.get_index_path()) {
94-
Ok(()) => Ok(()),
95-
Err(_) => Ok(())
94+
Ok(()) | Err(_) => Ok(())
9695
},
9796
Err(err) => Err(DatabaseError::from_io_error(err))
9897
}
@@ -138,7 +137,7 @@ impl Log {
138137
for line in reader.lines() {
139138
match line {
140139
Ok(line) => {
141-
let parts: Vec<_> = line.split(" ").collect();
140+
let parts: Vec<_> = line.split(' ').collect();
142141
let line_count: u64 = parts[0].parse().unwrap();
143142
let byte_count: u64 = parts[1].parse().unwrap();
144143
index.insert(line_count, byte_count);

exar-core/src/routing_strategy.rs

+7-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#[cfg(feature = "rustc-serialization")] use rustc_serialize::{Encoder, Encodable, Decoder, Decodable};
22
#[cfg(feature = "serde-serialization")] use serde::{Serialize, Serializer, Deserialize, Deserializer};
33
#[cfg(feature = "serde-serialization")] use serde::de::{Error, Visitor};
4+
#[cfg(feature = "serde-serialization")] use std::fmt;
45

56
/// A list specifying categories of routing strategy.
67
#[derive(Clone, Debug, PartialEq, Eq)]
@@ -36,7 +37,7 @@ impl Decodable for RoutingStrategy {
3637

3738
#[cfg(feature = "serde-serialization")]
3839
impl Serialize for RoutingStrategy {
39-
fn serialize<S: Serializer>(&self, serializer: &mut S) -> Result<(), S::Error> {
40+
fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
4041
match *self {
4142
RoutingStrategy::Random => serializer.serialize_str("Random"),
4243
RoutingStrategy::RoundRobin(_) => serializer.serialize_str("RoundRobin")
@@ -46,7 +47,7 @@ impl Serialize for RoutingStrategy {
4647

4748
#[cfg(feature = "serde-serialization")]
4849
impl Deserialize for RoutingStrategy {
49-
fn deserialize<D: Deserializer>(deserializer: &mut D) -> Result<Self, D::Error> {
50+
fn deserialize<D: Deserializer>(deserializer: D) -> Result<Self, D::Error> {
5051
deserializer.deserialize_str(RoutingStrategyVisitor)
5152
}
5253
}
@@ -57,7 +58,10 @@ struct RoutingStrategyVisitor;
5758
#[cfg(feature = "serde-serialization")]
5859
impl Visitor for RoutingStrategyVisitor {
5960
type Value = RoutingStrategy;
60-
fn visit_str<E: Error>(&mut self, s: &str) -> Result<RoutingStrategy, E> {
61+
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
62+
formatter.write_str("Random or RoundRobin")
63+
}
64+
fn visit_str<E: Error>(self, s: &str) -> Result<RoutingStrategy, E> {
6165
match s {
6266
"Random" => Ok(RoutingStrategy::Random),
6367
"RoundRobin" => Ok(RoutingStrategy::RoundRobin(0)),

exar-core/src/scanner.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ impl ScannerThread {
141141
ScannerAction::Stop => break 'main
142142
}
143143
}
144-
if self.subscriptions.len() != 0 {
144+
if !self.subscriptions.is_empty() {
145145
match self.scan() {
146146
Ok(_) => self.retain_active_subscriptions(),
147147
Err(err) => error!("Unable to scan log: {}", err)

exar-core/src/util.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ impl<T> Interval<T> {
4747

4848
impl Merge for Vec<Interval<u64>> {
4949
fn merge(&mut self) {
50-
if self.len() > 0 {
50+
if !self.is_empty() {
5151
self.sort_by(|a, b| a.start.cmp(&b.start));
5252
let mut merged_intervals = vec![ self[0].clone() ];
5353
for interval in self.iter().skip(1) {

exar-core/tests/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
extern crate exar;
22
extern crate rand;
33

4-
#[cfg(test)] #[macro_use]
4+
#[cfg(test)]
55
extern crate exar_testkit;
66

77
use exar::*;
@@ -11,7 +11,7 @@ use exar_testkit::*;
1111
fn integration_test() {
1212
let mut db = Database::new(DatabaseConfig::default());
1313

14-
let ref collection_name = random_collection_name();
14+
let collection_name = &random_collection_name();
1515
let connection = db.connect(collection_name).expect("Unable to connect");
1616

1717
let test_event = Event::new("data", vec!["tag1", "tag2"]);

exar-db/Cargo.toml

+1-5
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,6 @@ clap = "2.1"
1414
exar = { version = "0.1", path = "../exar-core", features = ["rustc-serialization"] }
1515
exar-server = { version = "0.1", path = "../exar-server", features = ["rustc-serialization"] }
1616
log = "0.3"
17-
log4rs = { version = "0.4", features = ["toml"] }
17+
log4rs = { version = "0.6", features = ["toml_format"] }
1818
rustc-serialize = "0.3"
1919
toml-config = "0.4"
20-
21-
[profile.release]
22-
debug = true
23-
opt-level = 3

exar-net/src/message.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ impl FromTabSeparatedStr for TcpMessage {
7777
let tags: String = try!(parser.parse_next());
7878
let timestamp = try!(parser.parse_next());
7979
let data: String = try!(parser.parse_next());
80-
let tags: Vec<_> = tags.split(" ").collect();
80+
let tags: Vec<_> = tags.split(' ').collect();
8181
Ok(TcpMessage::Publish(Event::new(&data, tags).with_timestamp(timestamp)))
8282
},
8383
"Published" => {
@@ -90,7 +90,7 @@ impl FromTabSeparatedStr for TcpMessage {
9090
let live = try!(parser.parse_next());
9191
let offset = try!(parser.parse_next());
9292
let mut limit = parser.parse_next().ok();
93-
if limit.unwrap_or(0) <= 0 { limit = None }
93+
if limit.unwrap_or(0) == 0 { limit = None }
9494
let tag = parser.parse_next().ok();
9595
Ok(TcpMessage::Subscribe(live, offset, limit, tag))
9696
},

exar-net/src/stream.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ impl<T: Read + Write + TryClone> TcpMessageStream<T> {
3333
match self.reader.read_line(&mut line) {
3434
Ok(_) => {
3535
let trimmed_line = line.trim();
36-
match TcpMessage::from_tab_separated_str(&trimmed_line) {
36+
match TcpMessage::from_tab_separated_str(trimmed_line) {
3737
Ok(message) => Ok(message),
3838
Err(err) => Err(DatabaseError::ParseError(err))
3939
}

exar-server/Cargo.toml

+3-3
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@ exar = { version = "0.1", path = "../exar-core" }
1414
exar-net = { version = "0.1", path = "../exar-net" }
1515
log = "0.3"
1616
rustc-serialize = { optional = true, version = "0.3" }
17-
serde = { optional = true, version = "0.7" }
18-
serde_macros = { optional = true, version = "0.7" }
17+
serde = { optional = true, version = "0.9" }
18+
serde_derive = { optional = true, version = "0.9" }
1919

2020
[features]
2121
rustc-serialization = ["rustc-serialize"]
22-
serde-serialization = ["serde", "serde_macros"]
22+
serde-serialization = ["serde", "serde_derive"]
2323

2424
[dev-dependencies]
2525
exar-testkit = { version = "0.1", path = "../exar-testkit" }

exar-server/src/lib.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
#![cfg_attr(feature = "serde-serialization", feature(custom_derive, plugin))]
2-
#![cfg_attr(feature = "serde-serialization", plugin(serde_macros))]
3-
41
//! # Exar DB's server
52
//! This module contains a server implementation that uses Exar DB's TCP protocol.
63
//!
@@ -31,8 +28,9 @@ extern crate exar_net;
3128

3229
#[cfg(feature = "rustc-serialization")] extern crate rustc_serialize;
3330
#[cfg(feature = "serde-serialization")] extern crate serde;
31+
#[cfg(feature = "serde-serialization")] #[macro_use] extern crate serde_derive;
3432

35-
#[cfg(test)] #[macro_use]
33+
#[cfg(test)]
3634
extern crate exar_testkit;
3735

3836
#[macro_use]

0 commit comments

Comments
 (0)