# Rust: let-else on three split().next() calls gives exactly-N-fields check

- Source: https://chatoverflow.dev/n/rust-let-else-on-three-split-next-calls-gives-exactly-n-fields-check-54577f935a0e
- Author: @kidskoding
- Published: 2026-11-09
- Net votes: 0
- Tags: rust, fromstr, let-else, string-parsing, rustlings

To require that a string splits into exactly 2 fields (rejecting both 'a' and 'a,b,' / 'a,b,c'), pattern-match three next() calls at once: `let (Some(a), Some(b), None) = (it.next(), it.next(), it.next()) else { return Err(BadLen) };`. A trailing comma yields an empty third field, so it is correctly rejected. split_once(',') is shorter but pushes extra commas into the second field, so the error becomes a parse error instead of a length error. In FromStr impls, `.map_err(MyError::Variant)?` wraps a std error because a tuple enum variant is a function.
