mirror of
https://github.com/actix/examples
synced 2024-12-05 03:01:55 +01:00
make code pass clippy
This commit is contained in:
parent
87f5f295b4
commit
a9230b0760
@ -38,9 +38,9 @@ const MAX_ASCII_VALUE: u8 = 0x7Fu8;
|
|||||||
const MIN_CONTINUATION: u8 = 0x80u8;
|
const MIN_CONTINUATION: u8 = 0x80u8;
|
||||||
const MAX_CONTINUATION: u8 = 0xBFu8;
|
const MAX_CONTINUATION: u8 = 0xBFu8;
|
||||||
|
|
||||||
const ERROR_INVALID_UTF8_SEQUENCE_MESSAGE: &'static str = "invalid utf-8 sequence";
|
const ERROR_INVALID_UTF8_SEQUENCE_MESSAGE: &str = "invalid utf-8 sequence";
|
||||||
|
|
||||||
#[derive(Debug, PartialEq)]
|
#[derive(Debug, Eq, PartialEq)]
|
||||||
pub enum ByteResult {
|
pub enum ByteResult {
|
||||||
Continuation,
|
Continuation,
|
||||||
First(usize),
|
First(usize),
|
||||||
@ -97,10 +97,7 @@ fn check_overflow(data: &[u8], expected_size: usize) -> bool {
|
|||||||
0x80
|
0x80
|
||||||
};
|
};
|
||||||
|
|
||||||
match (raw_1, raw_2) {
|
matches!((raw_1, raw_2), (0xE0, 0xA0..=0xBF) | (0xE1..=0xEC, 0x80..=0xBF) | (0xED, 0x80..=0x9F))
|
||||||
(0xE0, 0xA0..=0xBF) | (0xE1..=0xEC, 0x80..=0xBF) | (0xED, 0x80..=0x9F) => true,
|
|
||||||
_ => false,
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
let raw_2: u8 = if len >= 2 {
|
let raw_2: u8 = if len >= 2 {
|
||||||
data[1]
|
data[1]
|
||||||
@ -111,19 +108,18 @@ fn check_overflow(data: &[u8], expected_size: usize) -> bool {
|
|||||||
};
|
};
|
||||||
let raw_3: u8 = if len == 3 { data[2] } else { 0x80 };
|
let raw_3: u8 = if len == 3 { data[2] } else { 0x80 };
|
||||||
|
|
||||||
match (raw_1, raw_2, raw_3) {
|
matches!((raw_1, raw_2, raw_3),
|
||||||
(0xF0, 0x90..=0xBF, 0x80..=0xBF)
|
(0xF0, 0x90..=0xBF, 0x80..=0xBF) |
|
||||||
| (0xF1..=0xF3, 0x80..=0xBF, 0x80..=0xBF)
|
(0xF1..=0xF3, 0x80..=0xBF, 0x80..=0xBF) |
|
||||||
| (0xf4, 0x80..=0x8F, 0x80..=0xBF) => true,
|
(0xf4, 0x80..=0x8F, 0x80..=0xBF)
|
||||||
_ => false,
|
)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn check_byte(byte: u8) -> ByteResult {
|
fn check_byte(byte: u8) -> ByteResult {
|
||||||
if byte <= MAX_ASCII_VALUE {
|
if byte <= MAX_ASCII_VALUE {
|
||||||
ByteResult::Ok
|
ByteResult::Ok
|
||||||
} else if byte >= MIN_CONTINUATION && byte <= MAX_CONTINUATION {
|
} else if (MIN_CONTINUATION..=MAX_CONTINUATION).contains(&byte) {
|
||||||
ByteResult::Continuation
|
ByteResult::Continuation
|
||||||
} else if byte & UTF8_START_2_BYTE_SEQ_MASK == UTF8_2_BYTE_SEQ {
|
} else if byte & UTF8_START_2_BYTE_SEQ_MASK == UTF8_2_BYTE_SEQ {
|
||||||
ByteResult::First(2)
|
ByteResult::First(2)
|
||||||
|
@ -91,11 +91,8 @@ impl ContinuationBuffer {
|
|||||||
|
|
||||||
buffer.push(valid);
|
buffer.push(valid);
|
||||||
|
|
||||||
match message_overflow {
|
if let Some(message_overflow) = message_overflow {
|
||||||
Some(message_overflow) => {
|
_ = overflow.insert(message_overflow);
|
||||||
_ = overflow.insert(message_overflow);
|
|
||||||
}
|
|
||||||
None => {}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
@ -177,18 +174,15 @@ impl WebsocketActor {
|
|||||||
overflow: message_overflow,
|
overflow: message_overflow,
|
||||||
} = validate_utf8_bytes(data)?;
|
} = validate_utf8_bytes(data)?;
|
||||||
|
|
||||||
match message_overflow {
|
if let Some(bytes) = message_overflow {
|
||||||
Some(bytes) => {
|
return Err(ProtocolError::Io(std::io::Error::new(
|
||||||
return Err(ProtocolError::Io(std::io::Error::new(
|
std::io::ErrorKind::Other,
|
||||||
std::io::ErrorKind::Other,
|
format!(
|
||||||
format!(
|
"invalid utf-8 sequence of {} bytes from index {}",
|
||||||
"invalid utf-8 sequence of {} bytes from index {}",
|
bytes.len(),
|
||||||
bytes.len(),
|
valid.len()
|
||||||
valid.len()
|
),
|
||||||
),
|
)));
|
||||||
)));
|
|
||||||
}
|
|
||||||
_ => {}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ByteString::try_from(valid.clone()).map_err(|e| {
|
ByteString::try_from(valid.clone()).map_err(|e| {
|
||||||
|
Loading…
Reference in New Issue
Block a user