Skip to content

Commit 2a5a6b4

Browse files
Add missing code examples in libcore
1 parent 56d8a93 commit 2a5a6b4

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

library/core/src/num/dec2flt/mod.rs

+10
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,16 @@ from_str_float_impl!(f64);
166166
///
167167
/// This error is used as the error type for the [`FromStr`] implementation
168168
/// for [`f32`] and [`f64`].
169+
///
170+
/// # Example
171+
///
172+
/// ```
173+
/// use std::str::FromStr;
174+
///
175+
/// if let Err(e) = f64::from_str("a.12") {
176+
/// println!("Failed conversion to f64: {}", e);
177+
/// }
178+
/// ```
169179
#[derive(Debug, Clone, PartialEq, Eq)]
170180
#[stable(feature = "rust1", since = "1.0.0")]
171181
pub struct ParseFloatError {

library/core/src/num/mod.rs

+20
Original file line numberDiff line numberDiff line change
@@ -5286,13 +5286,33 @@ fn from_str_radix<T: FromStrRadixHelper>(src: &str, radix: u32) -> Result<T, Par
52865286
///
52875287
/// [`str.trim()`]: ../../std/primitive.str.html#method.trim
52885288
/// [`i8::from_str_radix`]: ../../std/primitive.i8.html#method.from_str_radix
5289+
///
5290+
/// # Example
5291+
///
5292+
/// ```
5293+
/// if let Err(e) = i32::from_str_radix("a12", 10) {
5294+
/// println!("Failed conversion to i32: {}", e);
5295+
/// }
5296+
/// ```
52895297
#[derive(Debug, Clone, PartialEq, Eq)]
52905298
#[stable(feature = "rust1", since = "1.0.0")]
52915299
pub struct ParseIntError {
52925300
kind: IntErrorKind,
52935301
}
52945302

52955303
/// Enum to store the various types of errors that can cause parsing an integer to fail.
5304+
///
5305+
/// # Example
5306+
///
5307+
/// ```
5308+
/// #![feature(int_error_matching)]
5309+
///
5310+
/// # fn main() {
5311+
/// if let Err(e) = i32::from_str_radix("a12", 10) {
5312+
/// println!("Failed conversion to i32: {:?}", e.kind());
5313+
/// }
5314+
/// # }
5315+
/// ```
52965316
#[unstable(
52975317
feature = "int_error_matching",
52985318
reason = "it can be useful to match errors when making error messages \

0 commit comments

Comments
 (0)