Skip to content

Commit de9440e

Browse files
committed
fix: Rust 1.77 compatibility, and clippy warning
1 parent c77f0a5 commit de9440e

3 files changed

Lines changed: 8 additions & 5 deletions

File tree

src/lib.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ impl Version {
3535
/// The magic bytes that indicate a PROXY Protocol v2 header.
3636
pub const MAGIC_V2: &'static [u8; 12] = b"\r\n\r\n\x00\r\nQUIT\n";
3737

38-
// #[inline]
38+
#[allow(clippy::result_unit_err)]
39+
#[inline]
3940
/// Peeks into the given buffer to determine if it contains a valid PROXY
4041
/// Protocol version magic.
4142
///
@@ -48,12 +49,14 @@ impl Version {
4849
const V1_MAGIC_LEN: usize = Version::MAGIC_V1.len();
4950
const V2_MAGIC_LEN: usize = Version::MAGIC_V2.len();
5051

52+
#[allow(overlapping_range_endpoints)]
53+
// Rust 1.77 doesn't support exclusive range endpoints in pattern matching.
5154
match buf.len() {
5255
0 => Ok(None),
53-
1..V2_MAGIC_LEN if Self::MAGIC_V2.starts_with(buf) => Ok(None),
5456
V2_MAGIC_LEN.. if buf.starts_with(Self::MAGIC_V2) => Ok(Some(Self::V2)),
55-
1..V1_MAGIC_LEN if Self::MAGIC_V1.as_bytes().starts_with(buf) => Ok(None),
5657
V1_MAGIC_LEN.. if buf.starts_with(Self::MAGIC_V1.as_bytes()) => Ok(Some(Self::V1)),
58+
1..=V2_MAGIC_LEN if Self::MAGIC_V2.starts_with(buf) => Ok(None),
59+
1..=V1_MAGIC_LEN if Self::MAGIC_V1.as_bytes().starts_with(buf) => Ok(None),
5760
_ => Err(()),
5861
}
5962
}

src/v2.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ impl Header {
7676
#[cfg(feature = "feat-codec-decode")]
7777
#[inline]
7878
/// See [`HeaderDecoder::decode`].
79-
pub fn decode<'a>(encoded: &'a [u8]) -> Result<Decoded<'a>, DecodeError> {
79+
pub fn decode(encoded: &[u8]) -> Result<Decoded<'_>, DecodeError> {
8080
HeaderDecoder::decode(encoded)
8181
}
8282
}

src/v2/codec/decode.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ impl HeaderDecoder {
8383
/// When there're extensions in the PROXY Protocol v2 header, the caller
8484
/// SHOULD read the extensions to check if they are malformed or not.
8585
/// See [`DecodedExtensions`] for more details.
86-
pub fn decode<'a>(buf: &'a [u8]) -> Result<Decoded<'a>, DecodeError> {
86+
pub fn decode(buf: &[u8]) -> Result<Decoded<'_>, DecodeError> {
8787
// 1. Magic bytes
8888
{
8989
let magic_length = min(Header::MAGIC.len(), buf.len());

0 commit comments

Comments
 (0)