Skip to content

Commit 44ad4c4

Browse files
committed
Make clippy happy
1 parent 68a8e07 commit 44ad4c4

File tree

4 files changed

+37
-37
lines changed

4 files changed

+37
-37
lines changed

src/bson.rs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ impl Debug for Bson {
106106
Bson::I64(v) => write!(f, "I64({:?})", v),
107107
Bson::TimeStamp(i) => {
108108
let time = (i >> 32) as i32;
109-
let inc = (i & 0xFFFFFFFF) as i32;
109+
let inc = (i & 0xFFFF_FFFF) as i32;
110110

111111
write!(f, "TimeStamp({}, {})", time, inc)
112112
}
@@ -296,19 +296,19 @@ impl From<Bson> for Value {
296296
Bson::Boolean(v) => json!(v),
297297
Bson::Null => Value::Null,
298298
Bson::RegExp(pat, opt) => json!({
299-
"$regex": pat,
300-
"$options": opt
301-
}),
299+
"$regex": pat,
300+
"$options": opt
301+
}),
302302
Bson::JavaScriptCode(code) => json!({ "$code": code }),
303303
Bson::JavaScriptCodeWithScope(code, scope) => json!({
304-
"$code": code,
305-
"scope": scope
306-
}),
304+
"$code": code,
305+
"scope": scope
306+
}),
307307
Bson::I32(v) => v.into(),
308308
Bson::I64(v) => v.into(),
309309
Bson::TimeStamp(v) => {
310310
let time = v >> 32;
311-
let inc = v & 0x0000FFFF;
311+
let inc = v & 0x0000_FFFF;
312312
json!({
313313
"t": time,
314314
"i": inc
@@ -323,10 +323,10 @@ impl From<Bson> for Value {
323323
}
324324
Bson::ObjectId(v) => json!({"$oid": v.to_string()}),
325325
Bson::UtcDatetime(v) => json!({
326-
"$date": {
327-
"$numberLong": (v.timestamp() * 1000) + ((v.nanosecond() / 1000000) as i64)
328-
}
329-
}),
326+
"$date": {
327+
"$numberLong": (v.timestamp() * 1000) + ((v.nanosecond() / 1000000) as i64)
328+
}
329+
}),
330330
// FIXME: Don't know what is the best way to encode Symbol type
331331
Bson::Symbol(v) => json!({ "$symbol": v }),
332332
Bson::Decimal128(ref v) => json!({ "$numberDecimal": v.to_string() }),
@@ -403,7 +403,7 @@ impl Bson {
403403
}
404404
Bson::TimeStamp(v) => {
405405
let time = (v >> 32) as i32;
406-
let inc = (v & 0xFFFFFFFF) as i32;
406+
let inc = (v & 0xFFFF_FFFF) as i32;
407407

408408
doc! {
409409
"t": time,
@@ -470,7 +470,7 @@ impl Bson {
470470
} else if let Ok(long) = values.get_document("$date")
471471
.and_then(|inner| inner.get_i64("$numberLong"))
472472
{
473-
return Bson::UtcDatetime(Utc.timestamp(long / 1000, ((long % 1000) * 1000000) as u32));
473+
return Bson::UtcDatetime(Utc.timestamp(long / 1000, ((long % 1000) * 1_000_000) as u32));
474474
} else if let Ok(sym) = values.get_str("$symbol") {
475475
return Bson::Symbol(sym.to_owned());
476476
} else if let Ok(dec) = values.get_str("$numberDecimal") {

src/encoder/error.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use bson::Bson;
22
use serde::ser;
3-
use std::{error, fmt, io};
43
use std::fmt::Display;
4+
use std::{error, fmt, io};
55

66
/// Possible errors that can arise during encoding.
77
#[derive(Debug)]
@@ -27,10 +27,10 @@ impl fmt::Display for EncoderError {
2727
EncoderError::Unknown(ref inner) => inner.fmt(fmt),
2828
EncoderError::UnsupportedUnsignedType => fmt.write_str("BSON does not support unsigned type"),
2929
EncoderError::UnsignedTypesValueExceedsRange(value) => write!(
30-
fmt,
31-
"BSON does not support unsigned types.
30+
fmt,
31+
"BSON does not support unsigned types.
3232
An attempt to encode the value: {} in a signed type failed due to the value's size.",
33-
value
33+
value
3434
),
3535
}
3636
}
@@ -43,14 +43,16 @@ impl error::Error for EncoderError {
4343
EncoderError::InvalidMapKeyType(_) => "Invalid map key type",
4444
EncoderError::Unknown(ref inner) => inner,
4545
EncoderError::UnsupportedUnsignedType => "BSON does not support unsigned type",
46-
EncoderError::UnsignedTypesValueExceedsRange(_) => "BSON does not support unsigned types.
46+
EncoderError::UnsignedTypesValueExceedsRange(_) => {
47+
"BSON does not support unsigned types.
4748
An attempt to encode the value: {} in a signed type failed due to the values size."
49+
}
4850
}
4951
}
5052

5153
fn cause(&self) -> Option<&error::Error> {
52-
match self {
53-
&EncoderError::IoError(ref inner) => Some(inner),
54+
match *self {
55+
EncoderError::IoError(ref inner) => Some(inner),
5456
_ => None,
5557
}
5658
}

src/encoder/serde.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -229,17 +229,17 @@ impl Serializer for Encoder {
229229

230230
#[inline]
231231
fn serialize_seq(self, len: Option<usize>) -> EncoderResult<Self::SerializeSeq> {
232-
Ok(ArraySerializer { inner: Array::with_capacity(len.unwrap_or(0)), })
232+
Ok(ArraySerializer { inner: Array::with_capacity(len.unwrap_or(0)) })
233233
}
234234

235235
#[inline]
236236
fn serialize_tuple(self, len: usize) -> EncoderResult<Self::SerializeTuple> {
237-
Ok(TupleSerializer { inner: Array::with_capacity(len), })
237+
Ok(TupleSerializer { inner: Array::with_capacity(len) })
238238
}
239239

240240
#[inline]
241241
fn serialize_tuple_struct(self, _name: &'static str, len: usize) -> EncoderResult<Self::SerializeTupleStruct> {
242-
Ok(TupleStructSerializer { inner: Array::with_capacity(len), })
242+
Ok(TupleStructSerializer { inner: Array::with_capacity(len) })
243243
}
244244

245245
#[inline]
@@ -250,13 +250,13 @@ impl Serializer for Encoder {
250250
len: usize)
251251
-> EncoderResult<Self::SerializeTupleVariant> {
252252
Ok(TupleVariantSerializer { inner: Array::with_capacity(len),
253-
name: variant, })
253+
name: variant })
254254
}
255255

256256
#[inline]
257257
fn serialize_map(self, _len: Option<usize>) -> EncoderResult<Self::SerializeMap> {
258258
Ok(MapSerializer { inner: Document::new(),
259-
next_key: None, })
259+
next_key: None })
260260
}
261261

262262
#[inline]
@@ -272,7 +272,7 @@ impl Serializer for Encoder {
272272
_len: usize)
273273
-> EncoderResult<Self::SerializeStructVariant> {
274274
Ok(StructVariantSerializer { name: variant,
275-
inner: Document::new(), })
275+
inner: Document::new() })
276276
}
277277
}
278278

src/oid.rs

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
33
use libc;
44

5-
use std::sync::atomic::{AtomicUsize, Ordering, ATOMIC_USIZE_INIT};
5+
use std::sync::atomic::{AtomicUsize, Ordering};
66
use std::{error, fmt, io, result};
77

88
use byteorder::{BigEndian, ByteOrder, LittleEndian};
@@ -25,9 +25,9 @@ const MACHINE_ID_OFFSET: usize = TIMESTAMP_OFFSET + TIMESTAMP_SIZE;
2525
const PROCESS_ID_OFFSET: usize = MACHINE_ID_OFFSET + MACHINE_ID_SIZE;
2626
const COUNTER_OFFSET: usize = PROCESS_ID_OFFSET + PROCESS_ID_SIZE;
2727

28-
const MAX_U24: usize = 0xFFFFFF;
28+
const MAX_U24: usize = 0xFF_FFFF;
2929

30-
static OID_COUNTER: AtomicUsize = ATOMIC_USIZE_INIT;
30+
static OID_COUNTER: AtomicUsize = AtomicUsize::new(0);
3131
static mut MACHINE_BYTES: Option<[u8; 3]> = None;
3232

3333
/// Errors that can occur during OID construction and generation.
@@ -130,9 +130,7 @@ impl ObjectId {
130130
Err(Error::ArgumentError("Provided string must be a 12-byte hexadecimal string.".to_owned()))
131131
} else {
132132
let mut byte_array: [u8; 12] = [0; 12];
133-
for i in 0..12 {
134-
byte_array[i] = bytes[i];
135-
}
133+
byte_array[..].copy_from_slice(&bytes[..]);
136134
Ok(ObjectId::with_bytes(byte_array))
137135
}
138136
}
@@ -203,7 +201,7 @@ impl ObjectId {
203201
// will have the same MACHINE_BYTES result.
204202
unsafe {
205203
if let Some(bytes) = MACHINE_BYTES.as_ref() {
206-
return Ok(bytes.clone());
204+
return Ok(*bytes);
207205
}
208206
}
209207

@@ -219,9 +217,9 @@ impl ObjectId {
219217
// Re-convert string to bytes and grab first three
220218
let mut bytes = hash.bytes();
221219
let mut vec: [u8; 3] = [0; 3];
222-
for i in 0..MACHINE_ID_SIZE {
220+
for v in &mut vec {
223221
match bytes.next() {
224-
Some(b) => vec[i] = b,
222+
Some(b) => *v = b,
225223
None => break,
226224
}
227225
}
@@ -287,7 +285,7 @@ fn pid_generation() {
287285

288286
#[test]
289287
fn count_generated_is_big_endian() {
290-
let start = 1122866;
288+
let start = 1_122_866;
291289
OID_COUNTER.store(start, Ordering::SeqCst);
292290

293291
// Test count generates correct value 1122866

0 commit comments

Comments
 (0)