diff --git a/wtransport-proto/src/bytes.rs b/wtransport-proto/src/bytes.rs index 9fde7d7..d200bff 100644 --- a/wtransport-proto/src/bytes.rs +++ b/wtransport-proto/src/bytes.rs @@ -173,7 +173,7 @@ impl<'a, 'b> BufferReaderChild<'a, 'b> { pub fn commit(self) { self.parent .skip(self.reader.offset()) - .expect("Child offset is bounded to parent") + .expect("Child offset is bounded to parent"); } #[inline(always)] diff --git a/wtransport-proto/src/error.rs b/wtransport-proto/src/error.rs index 2f3f568..318a658 100644 --- a/wtransport-proto/src/error.rs +++ b/wtransport-proto/src/error.rs @@ -133,6 +133,6 @@ mod qpack_error_codes { mod wt_error_codes { use crate::varint::VarInt; - pub const WEBTRANSPORT_BUFFERED_STREAM_REJECTED: VarInt = VarInt::from_u32(0x3994bd84); - pub const WEBTRANSPORT_SESSION_GONE: VarInt = VarInt::from_u32(0x170d7b68); + pub const WEBTRANSPORT_BUFFERED_STREAM_REJECTED: VarInt = VarInt::from_u32(0x3994_bd84); + pub const WEBTRANSPORT_SESSION_GONE: VarInt = VarInt::from_u32(0x170d_7b68); } diff --git a/wtransport-proto/src/frame.rs b/wtransport-proto/src/frame.rs index 8ea7d14..7429ec3 100644 --- a/wtransport-proto/src/frame.rs +++ b/wtransport-proto/src/frame.rs @@ -376,10 +376,10 @@ impl<'a> Frame<'a> { /// Panics if the `payload` size if greater than [`VarInt::MAX`]. fn new(kind: FrameKind, payload: Cow<'a, [u8]>, session_id: Option) -> Self { if let FrameKind::Exercise(id) = kind { - debug_assert!(FrameKind::is_id_exercise(id)) + debug_assert!(FrameKind::is_id_exercise(id)); } else if let FrameKind::WebTransport = kind { debug_assert!(payload.is_empty()); - debug_assert!(session_id.is_some()) + debug_assert!(session_id.is_some()); } assert!(payload.len() <= VarInt::MAX.into_inner() as usize); @@ -590,7 +590,7 @@ mod tests { #[test] fn unknown_frame() { - let buffer = Frame::serialize_any(VarInt::from_u32(0x424242), b"This is a test payload"); + let buffer = Frame::serialize_any(VarInt::from_u32(0x0042_4242), b"This is a test payload"); assert!(matches!( Frame::read(&mut buffer.as_slice()).unwrap(), @@ -600,7 +600,7 @@ mod tests { #[tokio::test] async fn unknown_frame_async() { - let buffer = Frame::serialize_any(VarInt::from_u32(0x424242), b"This is a test payload"); + let buffer = Frame::serialize_any(VarInt::from_u32(0x0042_4242), b"This is a test payload"); assert!(matches!( Frame::read_async(&mut buffer.as_slice()).await, diff --git a/wtransport-proto/src/ids.rs b/wtransport-proto/src/ids.rs index 21ecced..7540d8d 100644 --- a/wtransport-proto/src/ids.rs +++ b/wtransport-proto/src/ids.rs @@ -157,7 +157,8 @@ pub struct QStreamId(VarInt); impl QStreamId { /// The largest quarter stream id. // SAFETY: value is less than max varint - pub const MAX: QStreamId = unsafe { Self(VarInt::from_u64_unchecked(1152921504606846975)) }; + pub const MAX: QStreamId = + unsafe { Self(VarInt::from_u64_unchecked(1_152_921_504_606_846_975)) }; /// Creates a quarter stream id from its corresponding [`SessionId`] #[inline(always)] @@ -281,8 +282,8 @@ impl TryFrom for StatusCode { type Error = InvalidStatusCode; fn try_from(value: u8) -> Result { - if value as u16 >= Self::MIN.0 && value as u16 <= Self::MAX.0 { - Ok(Self(value as u16)) + if u16::from(value) >= Self::MIN.0 && u16::from(value) <= Self::MAX.0 { + Ok(Self(u16::from(value))) } else { Err(InvalidStatusCode) } @@ -305,7 +306,7 @@ impl TryFrom for StatusCode { type Error = InvalidStatusCode; fn try_from(value: u32) -> Result { - if value >= Self::MIN.0 as u32 && value <= Self::MAX.0 as u32 { + if value >= u32::from(Self::MIN.0) && value <= u32::from(Self::MAX.0) { Ok(Self(value as u16)) } else { Err(InvalidStatusCode) @@ -317,7 +318,7 @@ impl TryFrom for StatusCode { type Error = InvalidStatusCode; fn try_from(value: u64) -> Result { - if value >= Self::MIN.0 as u64 && value <= Self::MAX.0 as u64 { + if value >= u64::from(Self::MIN.0) && value <= u64::from(Self::MAX.0) { Ok(Self(value as u16)) } else { Err(InvalidStatusCode) diff --git a/wtransport-proto/src/session.rs b/wtransport-proto/src/session.rs index a7aaf0e..a5e9b87 100644 --- a/wtransport-proto/src/session.rs +++ b/wtransport-proto/src/session.rs @@ -245,7 +245,7 @@ impl SessionResponse { K: ToString, V: ToString, { - self.0.insert(key, value) + self.0.insert(key, value); } /// Returns the whole headers associated with the request. diff --git a/wtransport-proto/src/settings.rs b/wtransport-proto/src/settings.rs index 0c1c337..46e0ce0 100644 --- a/wtransport-proto/src/settings.rs +++ b/wtransport-proto/src/settings.rs @@ -244,6 +244,6 @@ mod setting_ids { pub const SETTINGS_QPACK_BLOCKED_STREAMS: VarInt = VarInt::from_u32(0x07); pub const SETTINGS_ENABLE_CONNECT_PROTOCOL: VarInt = VarInt::from_u32(0x08); pub const SETTINGS_H3_DATAGRAM: VarInt = VarInt::from_u32(0x33); - pub const SETTINGS_ENABLE_WEBTRANSPORT: VarInt = VarInt::from_u32(0x2b603742); - pub const SETTINGS_WEBTRANSPORT_MAX_SESSIONS: VarInt = VarInt::from_u32(0xc671706a); + pub const SETTINGS_ENABLE_WEBTRANSPORT: VarInt = VarInt::from_u32(0x2b60_3742); + pub const SETTINGS_WEBTRANSPORT_MAX_SESSIONS: VarInt = VarInt::from_u32(0xc671_706a); } diff --git a/wtransport-proto/src/stream.rs b/wtransport-proto/src/stream.rs index 167bb2a..9ddeba2 100644 --- a/wtransport-proto/src/stream.rs +++ b/wtransport-proto/src/stream.rs @@ -131,9 +131,9 @@ pub mod biremote { Err(frame::IoReadError::IO(io_error)) => { if matches!(io_error, bytes::IoReadError::UnexpectedFin) { return Err(IoReadError::H3(ErrorCode::Frame)); - } else { - return Err(IoReadError::IO(io_error)); } + + return Err(IoReadError::IO(io_error)); } } } @@ -319,9 +319,9 @@ pub mod bilocal { Err(frame::IoReadError::IO(io_error)) => { if matches!(io_error, bytes::IoReadError::UnexpectedFin) { return Err(IoReadError::H3(ErrorCode::Frame)); - } else { - return Err(IoReadError::IO(io_error)); } + + return Err(IoReadError::IO(io_error)); } } } @@ -642,9 +642,9 @@ pub mod uniremote { Err(frame::IoReadError::IO(io_error)) => { if matches!(io_error, bytes::IoReadError::UnexpectedFin) { return Err(IoReadError::H3(ErrorCode::Frame)); - } else { - return Err(IoReadError::IO(io_error)); } + + return Err(IoReadError::IO(io_error)); } } } @@ -965,9 +965,9 @@ pub mod session { Err(frame::IoReadError::IO(io_error)) => { if matches!(io_error, bytes::IoReadError::UnexpectedFin) { return Err(IoReadError::H3(ErrorCode::Frame)); - } else { - return Err(IoReadError::IO(io_error)); } + + return Err(IoReadError::IO(io_error)); } } } diff --git a/wtransport-proto/src/stream_header.rs b/wtransport-proto/src/stream_header.rs index b816f75..7950f93 100644 --- a/wtransport-proto/src/stream_header.rs +++ b/wtransport-proto/src/stream_header.rs @@ -381,13 +381,13 @@ mod tests { #[test] fn read_eof() { - let buffer = StreamHeader::serialize_any(VarInt::from_u32(0x424242)); + let buffer = StreamHeader::serialize_any(VarInt::from_u32(0x0042_4242)); assert!(StreamHeader::read(&mut &buffer[..buffer.len() - 1]).is_none()); } #[tokio::test] async fn read_eof_async() { - let buffer = StreamHeader::serialize_any(VarInt::from_u32(0x424242)); + let buffer = StreamHeader::serialize_any(VarInt::from_u32(0x0042_4242)); for len in 0..buffer.len() { let result = StreamHeader::read_async(&mut &buffer[..len]).await; @@ -428,7 +428,7 @@ mod tests { #[test] fn unknown_stream() { - let buffer = StreamHeader::serialize_any(VarInt::from_u32(0x424242)); + let buffer = StreamHeader::serialize_any(VarInt::from_u32(0x0042_4242)); assert!(matches!( StreamHeader::read(&mut buffer.as_slice()).unwrap(), @@ -438,7 +438,7 @@ mod tests { #[tokio::test] async fn unknown_stream_async() { - let buffer = StreamHeader::serialize_any(VarInt::from_u32(0x424242)); + let buffer = StreamHeader::serialize_any(VarInt::from_u32(0x0042_4242)); assert!(matches!( StreamHeader::read_async(&mut buffer.as_slice()).await, diff --git a/wtransport-proto/src/varint.rs b/wtransport-proto/src/varint.rs index 5c4aa58..741bc76 100644 --- a/wtransport-proto/src/varint.rs +++ b/wtransport-proto/src/varint.rs @@ -12,7 +12,7 @@ pub struct VarInt(u64); impl VarInt { /// The largest value that can be represented by this integer type. - pub const MAX: Self = Self(4611686018427387903); + pub const MAX: Self = Self(4_611_686_018_427_387_903); /// The smallest value that can be represented by this integer type. pub const MIN: Self = Self(0); @@ -86,14 +86,14 @@ impl VarInt { impl From for VarInt { #[inline(always)] fn from(value: u8) -> Self { - Self::from_u32(value as u32) + Self::from_u32(u32::from(value)) } } impl From for VarInt { #[inline(always)] fn from(value: u16) -> Self { - Self::from_u32(value as u32) + Self::from_u32(u32::from(value)) } } @@ -155,11 +155,18 @@ mod tests { assert!((2..=VarInt::MAX_SIZE).contains(&VarInt::try_from_u64(16383).unwrap().size())); assert!((4..=VarInt::MAX_SIZE).contains(&VarInt::try_from_u64(16384).unwrap().size())); - assert!((4..=VarInt::MAX_SIZE).contains(&VarInt::try_from_u64(1073741823).unwrap().size())); - - assert!((8..=VarInt::MAX_SIZE).contains(&VarInt::try_from_u64(1073741824).unwrap().size())); - assert!((8..=VarInt::MAX_SIZE) - .contains(&VarInt::try_from_u64(4611686018427387903).unwrap().size())); + assert!( + (4..=VarInt::MAX_SIZE).contains(&VarInt::try_from_u64(1_073_741_823).unwrap().size()) + ); + + assert!( + (8..=VarInt::MAX_SIZE).contains(&VarInt::try_from_u64(1_073_741_824).unwrap().size()) + ); + assert!((8..=VarInt::MAX_SIZE).contains( + &VarInt::try_from_u64(4_611_686_018_427_387_903) + .unwrap() + .size() + )); assert_eq!(VarInt::MAX_SIZE, 8); assert_eq!(VarInt::MAX.size(), VarInt::MAX_SIZE); diff --git a/wtransport/src/driver/mod.rs b/wtransport/src/driver/mod.rs index e424328..fd7134b 100644 --- a/wtransport/src/driver/mod.rs +++ b/wtransport/src/driver/mod.rs @@ -127,18 +127,18 @@ impl Driver { if stream.session_id() == session_id { return Ok(stream); - } else { - debug!( - "Discarding WT stream (stream_id: {}, session_id: {})", - stream.id(), - stream.session_id() - ); - - stream - .into_stream() - .stop(ErrorCode::BufferedStreamRejected.to_code()) - .expect("Stream not already stopped"); } + + debug!( + "Discarding WT stream (stream_id: {}, session_id: {})", + stream.id(), + stream.session_id() + ); + + stream + .into_stream() + .stop(ErrorCode::BufferedStreamRejected.to_code()) + .expect("Stream not already stopped"); } } @@ -153,19 +153,19 @@ impl Driver { if stream.session_id() == session_id { return Ok(stream); - } else { - debug!( - "Discarding WT stream (stream_id: {}, session_id: {})", - stream.id(), - stream.session_id() - ); - - stream - .into_stream() - .1 - .stop(ErrorCode::BufferedStreamRejected.to_code()) - .expect("Stream not already stopped"); } + + debug!( + "Discarding WT stream (stream_id: {}, session_id: {})", + stream.id(), + stream.session_id() + ); + + stream + .into_stream() + .1 + .stop(ErrorCode::BufferedStreamRejected.to_code()) + .expect("Stream not already stopped"); } } diff --git a/wtransport/src/driver/streams/mod.rs b/wtransport/src/driver/streams/mod.rs index 807490f..2f2998c 100644 --- a/wtransport/src/driver/streams/mod.rs +++ b/wtransport/src/driver/streams/mod.rs @@ -70,7 +70,7 @@ impl QuicSendStream { pub fn reset(mut self, error_code: VarInt) { self.0 .reset(varint_w2q(error_code)) - .expect("Stream has been already reset") + .expect("Stream has been already reset"); } #[inline(always)] diff --git a/wtransport/src/driver/utils.rs b/wtransport/src/driver/utils.rs index 4268a99..0ccddc4 100644 --- a/wtransport/src/driver/utils.rs +++ b/wtransport/src/driver/utils.rs @@ -74,7 +74,7 @@ where /// Awaits all subscribers are dead. #[inline(always)] pub async fn closed(&self) { - self.0.closed().await + self.0.closed().await; } /// Generates a new subscriber. diff --git a/wtransport/src/stream.rs b/wtransport/src/stream.rs index 0f8bc80..ac28df5 100644 --- a/wtransport/src/stream.rs +++ b/wtransport/src/stream.rs @@ -67,7 +67,7 @@ impl SendStream { /// impact on performance. #[inline(always)] pub fn set_priority(&self, priority: i32) { - self.0.set_priority(priority) + self.0.set_priority(priority); } /// Gets the priority of the send stream. @@ -83,7 +83,7 @@ impl SendStream { /// already been made to finish the stream, the peer may still receive all written data. #[inline(always)] pub fn reset(self, error_code: VarInt) { - self.0.reset(error_code) + self.0.reset(error_code); } /// Awaits for the stream to be stopped by the peer.