1
Fork 0

Rollup merge of #76747 - GuillaumeGomez:more-missing-libcore-code-examples, r=Mark-Simulacrum

Add missing code examples in libcore
This commit is contained in:
Tyler Mandry 2020-09-16 12:24:16 -07:00 committed by GitHub
commit ab78ca92f3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 30 additions and 0 deletions

View file

@ -166,6 +166,16 @@ from_str_float_impl!(f64);
/// ///
/// This error is used as the error type for the [`FromStr`] implementation /// This error is used as the error type for the [`FromStr`] implementation
/// for [`f32`] and [`f64`]. /// for [`f32`] and [`f64`].
///
/// # Example
///
/// ```
/// use std::str::FromStr;
///
/// if let Err(e) = f64::from_str("a.12") {
/// println!("Failed conversion to f64: {}", e);
/// }
/// ```
#[derive(Debug, Clone, PartialEq, Eq)] #[derive(Debug, Clone, PartialEq, Eq)]
#[stable(feature = "rust1", since = "1.0.0")] #[stable(feature = "rust1", since = "1.0.0")]
pub struct ParseFloatError { pub struct ParseFloatError {

View file

@ -5286,6 +5286,14 @@ fn from_str_radix<T: FromStrRadixHelper>(src: &str, radix: u32) -> Result<T, Par
/// ///
/// [`str.trim()`]: ../../std/primitive.str.html#method.trim /// [`str.trim()`]: ../../std/primitive.str.html#method.trim
/// [`i8::from_str_radix`]: ../../std/primitive.i8.html#method.from_str_radix /// [`i8::from_str_radix`]: ../../std/primitive.i8.html#method.from_str_radix
///
/// # Example
///
/// ```
/// if let Err(e) = i32::from_str_radix("a12", 10) {
/// println!("Failed conversion to i32: {}", e);
/// }
/// ```
#[derive(Debug, Clone, PartialEq, Eq)] #[derive(Debug, Clone, PartialEq, Eq)]
#[stable(feature = "rust1", since = "1.0.0")] #[stable(feature = "rust1", since = "1.0.0")]
pub struct ParseIntError { pub struct ParseIntError {
@ -5293,6 +5301,18 @@ pub struct ParseIntError {
} }
/// Enum to store the various types of errors that can cause parsing an integer to fail. /// Enum to store the various types of errors that can cause parsing an integer to fail.
///
/// # Example
///
/// ```
/// #![feature(int_error_matching)]
///
/// # fn main() {
/// if let Err(e) = i32::from_str_radix("a12", 10) {
/// println!("Failed conversion to i32: {:?}", e.kind());
/// }
/// # }
/// ```
#[unstable( #[unstable(
feature = "int_error_matching", feature = "int_error_matching",
reason = "it can be useful to match errors when making error messages \ reason = "it can be useful to match errors when making error messages \