A bunch of minor documentation tweaks and fixes.
other
}
- /// Moves all the elements of `other` into `Self`, leaving `other` empty.
+ /// Moves all the elements of `other` into `self`, leaving `other` empty.
///
/// # Panics
///
///
/// let mut buf = VecDeque::new();
/// buf.extend(1..5);
- /// buf.retain(|&x| x%2 == 0);
+ /// buf.retain(|&x| x % 2 == 0);
/// assert_eq!(buf, [2, 4]);
/// ```
///
/// use std::f32;
///
/// let x = 2.0_f32;
- /// let abs_difference = (x.recip() - (1.0/x)).abs();
+ /// let abs_difference = (x.recip() - (1.0 / x)).abs();
///
/// assert!(abs_difference <= f32::EPSILON);
/// ```
///
/// ```
/// let x = 2.0_f64;
- /// let abs_difference = (x.recip() - (1.0/x)).abs();
+ /// let abs_difference = (x.recip() - (1.0 / x)).abs();
///
/// assert!(abs_difference < 1e-10);
/// ```
/// let b = 60.0_f32;
///
/// // 100.0
- /// let abs_difference = (m.mul_add(x, b) - (m*x + b)).abs();
+ /// let abs_difference = (m.mul_add(x, b) - ((m * x) + b)).abs();
///
/// assert!(abs_difference <= f32::EPSILON);
/// ```
/// use std::f32;
///
/// let x = 2.0_f32;
- /// let abs_difference = (x.powi(2) - x*x).abs();
+ /// let abs_difference = (x.powi(2) - (x * x)).abs();
///
/// assert!(abs_difference <= f32::EPSILON);
/// ```
/// use std::f32;
///
/// let x = 2.0_f32;
- /// let abs_difference = (x.powf(2.0) - x*x).abs();
+ /// let abs_difference = (x.powf(2.0) - (x * x)).abs();
///
/// assert!(abs_difference <= f32::EPSILON);
/// ```
/// ```
/// use std::f32;
///
- /// let x = f32::consts::PI/2.0;
+ /// let x = f32::consts::FRAC_PI_2;
///
/// let abs_difference = (x.sin() - 1.0).abs();
///
/// ```
/// use std::f32;
///
- /// let x = 2.0*f32::consts::PI;
+ /// let x = 2.0 * f32::consts::PI;
///
/// let abs_difference = (x.cos() - 1.0).abs();
///
/// ```
/// use std::f32;
///
- /// let x = f32::consts::PI / 4.0;
+ /// let x = f32::consts::FRAC_PI_4;
/// let abs_difference = (x.tan() - 1.0).abs();
///
/// assert!(abs_difference <= f32::EPSILON);
/// ```
/// use std::f32;
///
- /// let f = f32::consts::PI / 2.0;
+ /// let f = f32::consts::FRAC_PI_2;
///
/// // asin(sin(pi/2))
- /// let abs_difference = (f.sin().asin() - f32::consts::PI / 2.0).abs();
+ /// let abs_difference = (f.sin().asin() - f32::consts::FRAC_PI_2).abs();
///
/// assert!(abs_difference <= f32::EPSILON);
/// ```
/// ```
/// use std::f32;
///
- /// let f = f32::consts::PI / 4.0;
+ /// let f = f32::consts::FRAC_PI_4;
///
/// // acos(cos(pi/4))
- /// let abs_difference = (f.cos().acos() - f32::consts::PI / 4.0).abs();
+ /// let abs_difference = (f.cos().acos() - f32::consts::FRAC_PI_4).abs();
///
/// assert!(abs_difference <= f32::EPSILON);
/// ```
/// ```
/// use std::f32;
///
- /// let pi = f32::consts::PI;
/// // Positive angles measured counter-clockwise
/// // from positive x axis
/// // -pi/4 radians (45 deg clockwise)
/// let x2 = -3.0f32;
/// let y2 = 3.0f32;
///
- /// let abs_difference_1 = (y1.atan2(x1) - (-pi/4.0)).abs();
- /// let abs_difference_2 = (y2.atan2(x2) - 3.0*pi/4.0).abs();
+ /// let abs_difference_1 = (y1.atan2(x1) - (-f32::consts::FRAC_PI_4)).abs();
+ /// let abs_difference_2 = (y2.atan2(x2) - (3.0 * f32::consts::FRAC_PI_4)).abs();
///
/// assert!(abs_difference_1 <= f32::EPSILON);
/// assert!(abs_difference_2 <= f32::EPSILON);
/// ```
/// use std::f32;
///
- /// let x = f32::consts::PI/4.0;
+ /// let x = f32::consts::FRAC_PI_4;
/// let f = x.sin_cos();
///
/// let abs_difference_0 = (f.0 - x.sin()).abs();
///
/// let f = x.sinh();
/// // Solving sinh() at 1 gives `(e^2-1)/(2e)`
- /// let g = (e*e - 1.0)/(2.0*e);
+ /// let g = ((e * e) - 1.0) / (2.0 * e);
/// let abs_difference = (f - g).abs();
///
/// assert!(abs_difference <= f32::EPSILON);
/// let x = 1.0f32;
/// let f = x.cosh();
/// // Solving cosh() at 1 gives this result
- /// let g = (e*e + 1.0)/(2.0*e);
+ /// let g = ((e * e) + 1.0) / (2.0 * e);
/// let abs_difference = (f - g).abs();
///
/// // Same result
///
/// let f = x.tanh();
/// // Solving tanh() at 1 gives `(1 - e^(-2))/(1 + e^(-2))`
- /// let g = (1.0 - e.powi(-2))/(1.0 + e.powi(-2));
+ /// let g = (1.0 - e.powi(-2)) / (1.0 + e.powi(-2));
/// let abs_difference = (f - g).abs();
///
/// assert!(abs_difference <= f32::EPSILON);
/// let b = 60.0_f64;
///
/// // 100.0
- /// let abs_difference = (m.mul_add(x, b) - (m*x + b)).abs();
+ /// let abs_difference = (m.mul_add(x, b) - ((m * x) + b)).abs();
///
/// assert!(abs_difference < 1e-10);
/// ```
///
/// ```
/// let x = 2.0_f64;
- /// let abs_difference = (x.powi(2) - x*x).abs();
+ /// let abs_difference = (x.powi(2) - (x * x)).abs();
///
/// assert!(abs_difference < 1e-10);
/// ```
///
/// ```
/// let x = 2.0_f64;
- /// let abs_difference = (x.powf(2.0) - x*x).abs();
+ /// let abs_difference = (x.powf(2.0) - (x * x)).abs();
///
/// assert!(abs_difference < 1e-10);
/// ```
/// ```
/// use std::f64;
///
- /// let x = f64::consts::PI/2.0;
+ /// let x = f64::consts::FRAC_PI_2;
///
/// let abs_difference = (x.sin() - 1.0).abs();
///
/// ```
/// use std::f64;
///
- /// let x = 2.0*f64::consts::PI;
+ /// let x = 2.0 * f64::consts::PI;
///
/// let abs_difference = (x.cos() - 1.0).abs();
///
/// ```
/// use std::f64;
///
- /// let x = f64::consts::PI/4.0;
+ /// let x = f64::consts::FRAC_PI_4;
/// let abs_difference = (x.tan() - 1.0).abs();
///
/// assert!(abs_difference < 1e-14);
/// ```
/// use std::f64;
///
- /// let f = f64::consts::PI / 2.0;
+ /// let f = f64::consts::FRAC_PI_2;
///
/// // asin(sin(pi/2))
- /// let abs_difference = (f.sin().asin() - f64::consts::PI / 2.0).abs();
+ /// let abs_difference = (f.sin().asin() - f64::consts::FRAC_PI_2).abs();
///
/// assert!(abs_difference < 1e-10);
/// ```
/// ```
/// use std::f64;
///
- /// let f = f64::consts::PI / 4.0;
+ /// let f = f64::consts::FRAC_PI_4;
///
/// // acos(cos(pi/4))
- /// let abs_difference = (f.cos().acos() - f64::consts::PI / 4.0).abs();
+ /// let abs_difference = (f.cos().acos() - f64::consts::FRAC_PI_4).abs();
///
/// assert!(abs_difference < 1e-10);
/// ```
/// ```
/// use std::f64;
///
- /// let pi = f64::consts::PI;
/// // Positive angles measured counter-clockwise
/// // from positive x axis
/// // -pi/4 radians (45 deg clockwise)
/// let x2 = -3.0_f64;
/// let y2 = 3.0_f64;
///
- /// let abs_difference_1 = (y1.atan2(x1) - (-pi/4.0)).abs();
- /// let abs_difference_2 = (y2.atan2(x2) - 3.0*pi/4.0).abs();
+ /// let abs_difference_1 = (y1.atan2(x1) - (-f64::consts::FRAC_PI_4)).abs();
+ /// let abs_difference_2 = (y2.atan2(x2) - (3.0 * f64::consts::FRAC_PI_4)).abs();
///
/// assert!(abs_difference_1 < 1e-10);
/// assert!(abs_difference_2 < 1e-10);
/// ```
/// use std::f64;
///
- /// let x = f64::consts::PI/4.0;
+ /// let x = f64::consts::FRAC_PI_4;
/// let f = x.sin_cos();
///
/// let abs_difference_0 = (f.0 - x.sin()).abs();
///
/// let f = x.sinh();
/// // Solving sinh() at 1 gives `(e^2-1)/(2e)`
- /// let g = (e*e - 1.0)/(2.0*e);
+ /// let g = ((e * e) - 1.0) / (2.0 * e);
/// let abs_difference = (f - g).abs();
///
/// assert!(abs_difference < 1e-10);
/// let x = 1.0_f64;
/// let f = x.cosh();
/// // Solving cosh() at 1 gives this result
- /// let g = (e*e + 1.0)/(2.0*e);
+ /// let g = ((e * e) + 1.0) / (2.0 * e);
/// let abs_difference = (f - g).abs();
///
/// // Same result
///
/// let f = x.tanh();
/// // Solving tanh() at 1 gives `(1 - e^(-2))/(1 + e^(-2))`
- /// let g = (1.0 - e.powi(-2))/(1.0 + e.powi(-2));
+ /// let g = (1.0 - e.powi(-2)) / (1.0 + e.powi(-2));
/// let abs_difference = (f - g).abs();
///
/// assert!(abs_difference < 1.0e-10);
/// use std::ffi::{CString, CStr};
///
/// let c_string = CString::new(b"foo".to_vec()).expect("CString::new failed");
- /// let c_str = c_string.as_c_str();
- /// assert_eq!(c_str,
+ /// let cstr = c_string.as_c_str();
+ /// assert_eq!(cstr,
/// CStr::from_bytes_with_nul(b"foo\0").expect("CStr::from_bytes_with_nul failed"));
/// ```
#[inline]
/// ```
/// use std::ffi::CStr;
///
- /// let c_str = CStr::from_bytes_with_nul(b"hello");
- /// assert!(c_str.is_err());
+ /// let cstr = CStr::from_bytes_with_nul(b"hello");
+ /// assert!(cstr.is_err());
/// ```
///
/// Creating a `CStr` with an interior nul byte is an error:
/// ```
/// use std::ffi::CStr;
///
- /// let c_str = CStr::from_bytes_with_nul(b"he\0llo\0");
- /// assert!(c_str.is_err());
+ /// let cstr = CStr::from_bytes_with_nul(b"he\0llo\0");
+ /// assert!(cstr.is_err());
/// ```
#[stable(feature = "cstr_from_bytes", since = "1.10.0")]
pub fn from_bytes_with_nul(bytes: &[u8])
/// ```
/// use std::ffi::CStr;
///
- /// let c_str = CStr::from_bytes_with_nul(b"foo\0").expect("CStr::from_bytes_with_nul failed");
- /// assert_eq!(c_str.to_bytes(), b"foo");
+ /// let cstr = CStr::from_bytes_with_nul(b"foo\0").expect("CStr::from_bytes_with_nul failed");
+ /// assert_eq!(cstr.to_bytes(), b"foo");
/// ```
#[inline]
#[stable(feature = "rust1", since = "1.0.0")]
/// ```
/// use std::ffi::CStr;
///
- /// let c_str = CStr::from_bytes_with_nul(b"foo\0").expect("CStr::from_bytes_with_nul failed");
- /// assert_eq!(c_str.to_bytes_with_nul(), b"foo\0");
+ /// let cstr = CStr::from_bytes_with_nul(b"foo\0").expect("CStr::from_bytes_with_nul failed");
+ /// assert_eq!(cstr.to_bytes_with_nul(), b"foo\0");
/// ```
#[inline]
#[stable(feature = "rust1", since = "1.0.0")]
/// ```
/// use std::ffi::CStr;
///
- /// let c_str = CStr::from_bytes_with_nul(b"foo\0").expect("CStr::from_bytes_with_nul failed");
- /// assert_eq!(c_str.to_str(), Ok("foo"));
+ /// let cstr = CStr::from_bytes_with_nul(b"foo\0").expect("CStr::from_bytes_with_nul failed");
+ /// assert_eq!(cstr.to_str(), Ok("foo"));
/// ```
#[stable(feature = "cstr_to_str", since = "1.4.0")]
pub fn to_str(&self) -> Result<&str, str::Utf8Error> {
/// use std::borrow::Cow;
/// use std::ffi::CStr;
///
- /// let c_str = CStr::from_bytes_with_nul(b"Hello World\0")
+ /// let cstr = CStr::from_bytes_with_nul(b"Hello World\0")
/// .expect("CStr::from_bytes_with_nul failed");
- /// assert_eq!(c_str.to_string_lossy(), Cow::Borrowed("Hello World"));
+ /// assert_eq!(cstr.to_string_lossy(), Cow::Borrowed("Hello World"));
/// ```
///
/// Calling `to_string_lossy` on a `CStr` containing invalid UTF-8:
/// use std::borrow::Cow;
/// use std::ffi::CStr;
///
- /// let c_str = CStr::from_bytes_with_nul(b"Hello \xF0\x90\x80World\0")
+ /// let cstr = CStr::from_bytes_with_nul(b"Hello \xF0\x90\x80World\0")
/// .expect("CStr::from_bytes_with_nul failed");
/// assert_eq!(
- /// c_str.to_string_lossy(),
+ /// cstr.to_string_lossy(),
/// Cow::Owned(String::from("Hello �World")) as Cow<'_, str>
/// );
/// ```
/// ```
/// use std::ffi::OsString;
///
- /// let mut os_string = OsString::with_capacity(10);
+ /// let os_string = OsString::with_capacity(10);
/// assert!(os_string.capacity() >= 10);
/// ```
#[stable(feature = "osstring_simple_functions", since = "1.9.0")]
/// Note that this does **not** return the number of bytes in the string in
/// OS string form.
///
- /// The length returned is that of the underlying storage used by `OsStr`;
+ /// The length returned is that of the underlying storage used by `OsStr`.
/// As discussed in the [`OsString`] introduction, [`OsString`] and `OsStr`
/// store strings in a form best suited for cheap inter-conversion between
/// native-platform and Rust string forms, which may differ significantly