Skip to content

Commit c68440c

Browse files
authored
Add a potential cause raising ParseIntError.
Initially, I wanted to add it directly to the documentation of `str. parse()' method, I finally found that it was more relevant (I hope so?) to directly document the structure in question. I've added a scenario, in which we could all get caught at least once, to make it easier to diagnose the problem when parsing integers.
1 parent 1e1bfc7 commit c68440c

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

src/libcore/num/mod.rs

+6
Original file line numberDiff line numberDiff line change
@@ -3845,7 +3845,13 @@ fn from_str_radix<T: FromStrRadixHelper>(src: &str, radix: u32) -> Result<T, Par
38453845
///
38463846
/// This error is used as the error type for the `from_str_radix()` functions
38473847
/// on the primitive integer types, such as [`i8::from_str_radix`].
3848+
///
3849+
/// # Potential causes
38483850
///
3851+
/// Among other causes, `ParseIntError` can be thrown because of leading or trailing whitespaces in the string e.g. when it is getted from the standard input.
3852+
/// Using the [`str.trim()`] method ensures that no whitespace remains before parsing.
3853+
///
3854+
/// [`str.trim()`]: ../../std/primitive.str.html#method.trim
38493855
/// [`i8::from_str_radix`]: ../../std/primitive.i8.html#method.from_str_radix
38503856
#[derive(Debug, Clone, PartialEq, Eq)]
38513857
#[stable(feature = "rust1", since = "1.0.0")]

0 commit comments

Comments
 (0)