trait

Shl — overload << for place a flag in a bit position

Shl supplies the << operator. The trait consumes its receivers by value unless their types are references. Left shift moves bits toward higher positions; shifted-out bits are discarded for primitive integers. Validate the shift count or use checked_shl. Here a generic function delegates to the trait method on small primitive operands. Expected stdout (not executed): 8 Common mistake: Using a shift count at least the bit width. Static Rust 2024 example; not a verified ByteMind executable assessment.

Formal Syntax & Structure

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

Working Example

Example Snippetrust
use std::ops::Shl;fn combine<T, R, O>(left: T, right: R) -> O where T: Shl<R, Output=O> { left.shl(right) }fn main() { println!("{}", combine(1u32, 3u32)); }
Rust Reference