trait
ShlAssign — mutate a value with <<=
ShlAssign defines <<=, which modifies a mutable receiver and returns unit. It is a separate trait from the non-assignment operator. Move a flag left. The shift count must be within the bit width. This local wrapper delegates the operation to u32. Expected stdout (not executed): 16 Common mistake: Assuming implementing the matching binary trait automatically implements ShlAssign, or expecting <<= to return the updated value. Static Rust 2024 example; not a verified ByteMind executable assessment.
Formal Syntax & Structure
rust syntaxrust
fn shl_assign(&mut self, rhs: Rhs)Working Example
Example Snippetrust
use std::ops::ShlAssign;struct Value(u32);impl ShlAssign<u32> for Value { fn shl_assign(&mut self, rhs:u32) { self.0 <<= rhs; } }fn main() { let mut v=Value(1u32); v <<= 4u32; println!("{}",v.0); }