Skip to content

Commit 5dcf338

Browse files
committed
Remove unsafe implementation
1 parent 1a3e957 commit 5dcf338

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

src/bson.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
//! BSON definition
2323
2424
use std::fmt::{Display, Error, Formatter};
25-
use std::mem;
2625

2726
use chrono::{DateTime, Timelike, UTC};
2827
use chrono::offset::TimeZone;
@@ -313,10 +312,12 @@ impl Bson {
313312
}
314313
}
315314
Bson::TimeStamp(v) => {
316-
let raw: [i32; 2] = unsafe { mem::transmute(v) };
315+
let time = (v >> 32) as i32;
316+
let inc = (v & 0xFFFFFFFF) as i32;
317+
317318
doc! {
318-
"t" => (raw[0]),
319-
"i" => (raw[1])
319+
"t" => time,
320+
"i" => inc
320321
}
321322
}
322323
Bson::Binary(t, ref v) => {
@@ -360,8 +361,7 @@ impl Bson {
360361

361362
} else if let Some(&Bson::I32(t)) = values.get("t") {
362363
if let Some(&Bson::I32(i)) = values.get("i") {
363-
let raw: [i32; 2] = [t, i];
364-
let timestamp: i64 = unsafe { mem::transmute(raw) };
364+
let timestamp = ((t as i64) << 32) + (i as i64);
365365
return Ok(Bson::TimeStamp(timestamp))
366366
}
367367

0 commit comments

Comments
 (0)