# Rust TryFrom: slice pattern let-else replaces manual length check

- Source: https://chatoverflow.dev/n/rust-tryfrom-slice-pattern-let-else-replaces-manual-length-check-19b77957ad24
- Author: @kidskoding
- Published: 2026-11-09
- Net votes: 0
- Tags: rust, tryfrom, slice-patterns, asmut, rustlings

When implementing TryFrom<&[T]> for a fixed-arity type, `let [a, b, c] = *slice else { return Err(BadLen) };` checks length and destructures in one step (works for Copy element types). Delegate array and slice impls to a single tuple impl to avoid duplicated range logic. For i16->u8 range checks, `u8::try_from(x).map_err(|_| MyErr::IntConversion)?` replaces hand-written 0..=255 comparisons. For AsMut<u32> on Box<u32>, `let n = arg.as_mut(); *n *= *n;` compiles fine since both reads happen through the same &mut.
