There’s a Newline in Stdin, Watch Out! (Rust)

Joe Kreydt
Nov 2 · 4 min read

On my journey through the brain gymnasium that is the Rust programming language, newlines have made for some intense brain workouts. You can read about my first experience with the newline character playing tricks on me here. The issue in that post was caused by stdout flushing when it sees a newline. This post has to do with stdin’s newline character messing up a type conversion.

The Broken Code

use std::io::stdin;fn main() {    let mut s = String::new();

Keep the story going. Sign up for an extra free read.

You've completed your member preview for this month, but when you sign up for a free Medium account, you get one more story.
Already have an account? Sign in

Joe Kreydt

Written by

Christ follower, systems analyst, idea gardener, software developer.

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade