trait

Shr — overload >> for extract the high nibble

Shr supplies the >> operator. The trait consumes its receivers by value unless their types are references. Right shift moves bits toward lower positions. Signed primitive integers use arithmetic right shift; unsigned use logical right shift. Here a generic function delegates to the trait method on small primitive operands. Expected stdout (not executed): 10 Common mistake: Expecting signed right shift to fill with zero. Static Rust 2024 example; not a verified ByteMind executable assessment.

Formal Syntax & Structure

rust syntaxrust
T: std::ops::Shr<Rhs, Output = O>

Working Example

Example Snippetrust
use std::ops::Shr;fn combine<T, R, O>(left: T, right: R) -> O where T: Shr<R, Output=O> { left.shr(right) }fn main() { println!("{}", combine(0xABu8, 4u32)); }
Rust Reference