rust-lang / book

The Rust Programming Language

Home Page:https://doc.rust-lang.org/book/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Confused sentence in chapter two.

StefanSalewski opened this issue · comments

The sentence

The trim method on a String instance will eliminate any whitespace at the beginning and end, which we must do to be able to compare the string to the u32, which can only contain numerical data.

makes not much sense. Calling trim() by itself does not make the comparison to the numerical u32 value possible. Actually, trim() is needed to make parse() work successfully, as parse() might fail due to the terminating "\n" newline character.

I was just about to create this issue myself, but I see it is already here. The clause

The `trim` method on a `String` instance will eliminate any
whitespace at the beginning and end, which we must do to be able to compare the
string to the `u32`,

In ch02-00 implies (or at least has a strong implicature) that the trimmed String will be directly compared to the u32.

Instead we should be saying that we need to trim leading and trailing white space before we can use parse to construct an integer from the String.