Out od curiosity, why Rust insisted on the case?

⚓ rust    📅 2025-04-25    👤 surdeus    👁️ 3      

surdeus

I have the following code,

let (len, mut shift) = 
    match input[1] >> 1 {
        len @ 0..=125 => (len as u64, 2_usize),
        126 => (input[2] as u64 | (input[3] as u64) << 8, 4_usize),
        127 => (input[9] as u64 | (input[8] as u64)<<8 | (input[7] as u64)<<16 |
          (input[6] as u64)<<24 | (input[4] as u64)<<32 | (input[4] as u64)<<40 | (input[3] as u64)<<48 | (input[2] as u64)<<56, 10_usize),
        128_u8..=u8::MAX => todo!()
    };

Since I do the right shift on 1 and it isn't cyclic, the value can't exceed 127, however Rust insisted on the last condition. Why? Did I miss something?

4 posts - 3 participants

Read full topic

🏷️ rust_feed