trait
ShrAssign — mutate a value with >>=
ShrAssign defines >>=, which modifies a mutable receiver and returns unit. It is a separate trait from the non-assignment operator. Move a value right. Signed and unsigned right shifts differ; validate the count. This local wrapper delegates the operation to u32. Expected stdout (not executed): 8 Common mistake: Assuming implementing the matching binary trait automatically implements ShrAssign, or expecting >>= to return the updated value. Static Rust 2024 example; not a verified ByteMind executable assessment.
Formal Syntax & Structure
rust syntaxrust
fn shr_assign(&mut self, rhs: Rhs)Working Example
Example Snippetrust
use std::ops::ShrAssign;struct Value(u32);impl ShrAssign<u32> for Value { fn shr_assign(&mut self, rhs:u32) { self.0 >>= rhs; } }fn main() { let mut v=Value(32u32); v >>= 2u32; println!("{}",v.0); }