Skip to content

Commit

Permalink
clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
fafhrd91 committed Oct 9, 2023
1 parent ae1c184 commit 1c6bb68
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 10 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ frame-trace = []
ntex = "0.7.3"
ntex-amqp-codec = "0.9.0"

bitflags = "1.3"
bitflags = "2.4"
derive_more = "0.99"
log = "0.4"
pin-project-lite = "0.2"
Expand Down
12 changes: 8 additions & 4 deletions codec/src/codec/decode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ impl DecodeFormatted for char {
impl DecodeFormatted for DateTime<Utc> {
fn decode_with_format(input: &mut Bytes, fmt: u8) -> Result<Self, AmqpParseError> {
validate_code!(fmt, codec::FORMATCODE_TIMESTAMP);
be_read!(input, read_i64, 8).map(datetime_from_millis)
be_read!(input, read_i64, 8).and_then(datetime_from_millis)
}
}

Expand Down Expand Up @@ -520,17 +520,21 @@ fn decode_compound32(input: &mut Bytes) -> Result<CompoundHeader, AmqpParseError
Ok(CompoundHeader { size, count })
}

fn datetime_from_millis(millis: i64) -> DateTime<Utc> {
fn datetime_from_millis(millis: i64) -> Result<DateTime<Utc>, AmqpParseError> {
let seconds = millis / 1000;
if seconds < 0 {
// In order to handle time before 1970 correctly, we need to subtract a second
// and use the nanoseconds field to add it back. This is a result of the nanoseconds
// parameter being u32
let nanoseconds = ((1000 + (millis - (seconds * 1000))) * 1_000_000).unsigned_abs();
Utc.timestamp(seconds - 1, nanoseconds as u32)
Utc.timestamp_opt(seconds - 1, nanoseconds as u32)
.earliest()
.ok_or(AmqpParseError::DatetimeParseError)
} else {
let nanoseconds = ((millis - (seconds * 1000)) * 1_000_000).unsigned_abs();
Utc.timestamp(seconds, nanoseconds as u32)
Utc.timestamp_opt(seconds, nanoseconds as u32)
.earliest()
.ok_or(AmqpParseError::DatetimeParseError)
}
}

Expand Down
1 change: 1 addition & 0 deletions codec/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ pub enum AmqpParseError {
#[display(fmt = "Unknown {:?} option.", "_0")]
UnknownEnumOption(&'static str),
UuidParseError,
DatetimeParseError,
#[from(ignore)]
#[display(fmt = "Unexpected type: '{:?}'", "_0")]
UnexpectedType(&'static str),
Expand Down
2 changes: 1 addition & 1 deletion codec/src/message/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ mod message;
pub use self::body::MessageBody;
pub use self::message::Message;

pub(self) const SECTION_PREFIX_LENGTH: usize = 3;
const SECTION_PREFIX_LENGTH: usize = 3;
4 changes: 1 addition & 3 deletions src/dispatcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,7 @@ where

fn call_control_service(&self, frame: ControlFrame) {
let fut = self.ctl_service.call_static(frame.clone());
self.ctl_fut
.borrow_mut()
.push((frame, Box::pin(async move { fut.await })));
self.ctl_fut.borrow_mut().push((frame, Box::pin(fut)));
self.ctl_queue.waker.wake();
}

Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![deny(rust_2018_idioms)]
#![deny(rust_2018_idioms, warnings, unreachable_pub)]
#![allow(clippy::type_complexity)]

#[macro_use]
Expand Down

0 comments on commit 1c6bb68

Please sign in to comment.