Morse Code in Rust: Build a CLI Encoder and Decoder
Morse code is a small problem with a sharp edge. Encoding is a dictionary lookup; decoding is a dictionary lookup in reverse β until you add timing, and then it becomes a small state machine with real failure modes. Rust is an unusually good language for this shape of problem: enums model the signal states, Result forces you to decide what happens to bad input, and the whole tool compiles to a single binary you can hand to anyone.
In this article we will build a complete command-line Morse tool in Rust: encode text to dots and dashes, decode dots and dashes back to text, and handle the timing rules that make a decoder actually work. No external crates β just the standard library.
The table, as data
Every Morse implementation starts with the same table. In Rust it is a pair of match arms, or a static map.β¦