From 1a28237b4240f267a465e5179decbfdd7a26bf47 Mon Sep 17 00:00:00 2001 From: Corey Farwell Date: Mon, 6 Apr 2015 13:47:24 -0700 Subject: Alter libcore::result example to utilize closure param Since it doesn't utilize the parameter, it's not very idiomatic since it could just use the `Result::or` method. So this changes the example to utilize the parameter. As far as I can tell, all the numbers in this example are completely arbitrary. --- src/libcore/result.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/libcore') diff --git a/src/libcore/result.rs b/src/libcore/result.rs index 67a5ab891f7..4ac169f0068 100644 --- a/src/libcore/result.rs +++ b/src/libcore/result.rs @@ -69,7 +69,7 @@ //! let good_result: Result = good_result.and_then(|i| Ok(i == 11)); //! //! // Use `or_else` to handle the error. -//! let bad_result: Result = bad_result.or_else(|i| Ok(11)); +//! let bad_result: Result = bad_result.or_else(|i| Ok(i + 20)); //! //! // Consume the result and return the contents with `unwrap`. //! let final_awesome_result = good_result.unwrap(); -- cgit 1.4.1-3-g733a5 From f1515fabb027e901a5cb47826f12ba89db2df078 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Fri, 10 Apr 2015 19:23:22 +0200 Subject: Add Default trait for AtomicBool, AtomicIsize and AtomicUsize --- src/libcore/atomic.rs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'src/libcore') diff --git a/src/libcore/atomic.rs b/src/libcore/atomic.rs index ed35e095492..02f9ee506f9 100644 --- a/src/libcore/atomic.rs +++ b/src/libcore/atomic.rs @@ -78,12 +78,20 @@ use intrinsics; use cell::UnsafeCell; use marker::PhantomData; +use default::Default; + /// A boolean type which can be safely shared between threads. #[stable(feature = "rust1", since = "1.0.0")] pub struct AtomicBool { v: UnsafeCell, } +impl Default for AtomicBool { + fn default() -> AtomicBool { + ATOMIC_BOOL_INIT + } +} + unsafe impl Sync for AtomicBool {} /// A signed integer type which can be safely shared between threads. @@ -92,6 +100,12 @@ pub struct AtomicIsize { v: UnsafeCell, } +impl Default for AtomicIsize { + fn default() -> AtomicIsize { + ATOMIC_ISIZE_INIT + } +} + unsafe impl Sync for AtomicIsize {} /// An unsigned integer type which can be safely shared between threads. @@ -100,6 +114,12 @@ pub struct AtomicUsize { v: UnsafeCell, } +impl Default for AtomicUsize { + fn default() -> AtomicUsize { + ATOMIC_USIZE_INIT + } +} + unsafe impl Sync for AtomicUsize {} /// A raw pointer type which can be safely shared between threads. -- cgit 1.4.1-3-g733a5 From f329030b095aa30ce29be0c3459615d85506747b Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Fri, 10 Apr 2015 16:05:09 -0700 Subject: std: Stabilize the Utf8Error type The meaning of each variant of this enum was somewhat ambiguous and it's uncler that we wouldn't even want to add more enumeration values in the future. As a result this error has been altered to instead become an opaque structure. Learning about the "first invalid byte index" is still an unstable feature, but the type itself is now stable. --- src/libcollections/lib.rs | 1 + src/libcollections/string.rs | 16 ++++++---------- src/libcollectionstest/str.rs | 2 +- src/libcollectionstest/string.rs | 1 - src/libcore/str/mod.rs | 39 +++++++++++++++++---------------------- src/libstd/error.rs | 5 +---- 6 files changed, 26 insertions(+), 38 deletions(-) (limited to 'src/libcore') diff --git a/src/libcollections/lib.rs b/src/libcollections/lib.rs index 7658611d809..5179b04f882 100644 --- a/src/libcollections/lib.rs +++ b/src/libcollections/lib.rs @@ -40,6 +40,7 @@ #![feature(str_char)] #![feature(slice_patterns)] #![feature(debug_builders)] +#![feature(utf8_error)] #![cfg_attr(test, feature(rand, rustc_private, test, hash, collections))] #![cfg_attr(test, allow(deprecated))] // rand diff --git a/src/libcollections/string.rs b/src/libcollections/string.rs index 441d0f2c5df..9c9f2d628b8 100644 --- a/src/libcollections/string.rs +++ b/src/libcollections/string.rs @@ -132,7 +132,7 @@ impl String { /// /// let invalid_vec = vec![240, 144, 128]; /// let s = String::from_utf8(invalid_vec).err().unwrap(); - /// assert_eq!(s.utf8_error(), Utf8Error::TooShort); + /// let err = s.utf8_error(); /// assert_eq!(s.into_bytes(), [240, 144, 128]); /// ``` #[inline] @@ -156,14 +156,10 @@ impl String { /// ``` #[stable(feature = "rust1", since = "1.0.0")] pub fn from_utf8_lossy<'a>(v: &'a [u8]) -> Cow<'a, str> { - let mut i = 0; + let mut i; match str::from_utf8(v) { Ok(s) => return Cow::Borrowed(s), - Err(e) => { - if let Utf8Error::InvalidByte(firstbad) = e { - i = firstbad; - } - } + Err(e) => i = e.valid_up_to(), } const TAG_CONT_U8: u8 = 128; @@ -188,9 +184,9 @@ impl String { }; } - // subseqidx is the index of the first byte of the subsequence we're looking at. - // It's used to copy a bunch of contiguous good codepoints at once instead of copying - // them one by one. + // subseqidx is the index of the first byte of the subsequence we're + // looking at. It's used to copy a bunch of contiguous good codepoints + // at once instead of copying them one by one. let mut subseqidx = i; while i < total { diff --git a/src/libcollectionstest/str.rs b/src/libcollectionstest/str.rs index 15f15900e78..cacafab4e3c 100644 --- a/src/libcollectionstest/str.rs +++ b/src/libcollectionstest/str.rs @@ -1502,7 +1502,7 @@ fn test_str_from_utf8() { assert_eq!(from_utf8(xs), Ok("ศไทย中华Việt Nam")); let xs = b"hello\xFF"; - assert_eq!(from_utf8(xs), Err(Utf8Error::TooShort)); + assert!(from_utf8(xs).is_err()); } #[test] diff --git a/src/libcollectionstest/string.rs b/src/libcollectionstest/string.rs index 5d6aa8ac0dc..3184f842e9a 100644 --- a/src/libcollectionstest/string.rs +++ b/src/libcollectionstest/string.rs @@ -45,7 +45,6 @@ fn test_from_utf8() { let xs = b"hello\xFF".to_vec(); let err = String::from_utf8(xs).err().unwrap(); - assert_eq!(err.utf8_error(), Utf8Error::TooShort); assert_eq!(err.into_bytes(), b"hello\xff".to_vec()); } diff --git a/src/libcore/str/mod.rs b/src/libcore/str/mod.rs index 9bc760b56ec..fc623f21167 100644 --- a/src/libcore/str/mod.rs +++ b/src/libcore/str/mod.rs @@ -106,19 +106,19 @@ Section: Creating a string /// Errors which can occur when attempting to interpret a byte slice as a `str`. #[derive(Copy, Eq, PartialEq, Clone, Debug)] -#[unstable(feature = "core", - reason = "error enumeration recently added and definitions may be refined")] -pub enum Utf8Error { - /// An invalid byte was detected at the byte offset given. - /// - /// The offset is guaranteed to be in bounds of the slice in question, and - /// the byte at the specified offset was the first invalid byte in the - /// sequence detected. - InvalidByte(usize), +#[stable(feature = "rust1", since = "1.0.0")] +pub struct Utf8Error { + valid_up_to: usize, +} - /// The byte slice was invalid because more bytes were needed but no more - /// bytes were available. - TooShort, +impl Utf8Error { + /// Returns the index in the given string up to which valid UTF-8 was + /// verified. + /// + /// Starting at the index provided, but not necessarily at it precisely, an + /// invalid UTF-8 encoding sequence was found. + #[unstable(feature = "utf8_error", reason = "method just added")] + pub fn valid_up_to(&self) -> usize { self.valid_up_to } } /// Converts a slice of bytes to a string slice without performing any @@ -147,14 +147,7 @@ pub unsafe fn from_utf8_unchecked<'a>(v: &'a [u8]) -> &'a str { #[stable(feature = "rust1", since = "1.0.0")] impl fmt::Display for Utf8Error { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - match *self { - Utf8Error::InvalidByte(n) => { - write!(f, "invalid utf-8: invalid byte at index {}", n) - } - Utf8Error::TooShort => { - write!(f, "invalid utf-8: byte slice too short") - } - } + write!(f, "invalid utf-8: invalid byte near index {}", self.valid_up_to) } } @@ -1218,14 +1211,16 @@ fn run_utf8_validation_iterator(iter: &mut slice::Iter) // restore the iterator we had at the start of this codepoint. macro_rules! err { () => {{ *iter = old.clone(); - return Err(Utf8Error::InvalidByte(whole.len() - iter.as_slice().len())) + return Err(Utf8Error { + valid_up_to: whole.len() - iter.as_slice().len() + }) }}} macro_rules! next { () => { match iter.next() { Some(a) => *a, // we needed data, but there was none: error! - None => return Err(Utf8Error::TooShort), + None => err!(), } }} diff --git a/src/libstd/error.rs b/src/libstd/error.rs index c9babeb3230..96087bf1183 100644 --- a/src/libstd/error.rs +++ b/src/libstd/error.rs @@ -122,10 +122,7 @@ impl Error for str::ParseBoolError { #[stable(feature = "rust1", since = "1.0.0")] impl Error for str::Utf8Error { fn description(&self) -> &str { - match *self { - str::Utf8Error::TooShort => "invalid utf-8: not enough bytes", - str::Utf8Error::InvalidByte(..) => "invalid utf-8: corrupt contents", - } + "invalid utf-8: corrupt contents" } } -- cgit 1.4.1-3-g733a5 From 219f61bdd89cab251884d0645c07916343231b59 Mon Sep 17 00:00:00 2001 From: Robin Kruppe Date: Sun, 12 Apr 2015 18:07:15 +0200 Subject: Make Debug include the - in -0.0 --- src/libcore/fmt/float.rs | 120 +++++++++++----------------------------------- src/libcore/fmt/mod.rs | 46 +++++++++--------- src/test/run-pass/ifmt.rs | 8 +++- 3 files changed, 59 insertions(+), 115 deletions(-) (limited to 'src/libcore') diff --git a/src/libcore/fmt/float.rs b/src/libcore/fmt/float.rs index 5f19bc5be98..72c25c68040 100644 --- a/src/libcore/fmt/float.rs +++ b/src/libcore/fmt/float.rs @@ -1,4 +1,4 @@ -// Copyright 2013-2014 The Rust Project Developers. See the COPYRIGHT +// Copyright 2013-2015 The Rust Project Developers. See the COPYRIGHT // file at the top-level directory of this distribution and at // http://rust-lang.org/COPYRIGHT. // @@ -8,14 +8,10 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -#![allow(missing_docs)] - pub use self::ExponentFormat::*; pub use self::SignificantDigits::*; -pub use self::SignFormat::*; -use char; -use char::CharExt; +use char::{self, CharExt}; use fmt; use iter::Iterator; use num::{cast, Float, ToPrimitive}; @@ -46,50 +42,29 @@ pub enum SignificantDigits { DigExact(usize) } -/// How to emit the sign of a number. -pub enum SignFormat { - /// `-` will be printed for negative values, but no sign will be emitted - /// for positive numbers. - SignNeg -} - -const DIGIT_E_RADIX: u32 = ('e' as u32) - ('a' as u32) + 11; - -/// Converts a number to its string representation as a byte vector. -/// This is meant to be a common base implementation for all numeric string -/// conversion functions like `to_string()` or `to_str_radix()`. +/// Converts a float number to its string representation. +/// This is meant to be a common base implementation for various formatting styles. +/// The number is assumed to be non-negative, callers use `Formatter::pad_integral` +/// to add the right sign, if any. /// /// # Arguments /// -/// - `num` - The number to convert. Accepts any number that +/// - `num` - The number to convert (non-negative). Accepts any number that /// implements the numeric traits. -/// - `radix` - Base to use. Accepts only the values 2-36. If the exponential notation -/// is used, then this base is only used for the significand. The exponent -/// itself always printed using a base of 10. -/// - `negative_zero` - Whether to treat the special value `-0` as -/// `-0` or as `+0`. -/// - `sign` - How to emit the sign. See `SignFormat`. /// - `digits` - The amount of digits to use for emitting the fractional /// part, if any. See `SignificantDigits`. /// - `exp_format` - Whether or not to use the exponential (scientific) notation. /// See `ExponentFormat`. /// - `exp_capital` - Whether or not to use a capital letter for the exponent sign, if /// exponential notation is desired. -/// - `f` - A closure to invoke with the bytes representing the +/// - `f` - A closure to invoke with the string representing the /// float. /// /// # Panics /// -/// - Panics if `radix` < 2 or `radix` > 36. -/// - Panics if `radix` > 14 and `exp_format` is `ExpDec` due to conflict -/// between digit and exponent sign `'e'`. -/// - Panics if `radix` > 25 and `exp_format` is `ExpBin` due to conflict -/// between digit and exponent sign `'p'`. +/// - Panics if `num` is negative. pub fn float_to_str_bytes_common( num: T, - radix: u32, - negative_zero: bool, - sign: SignFormat, digits: SignificantDigits, exp_format: ExponentFormat, exp_upper: bool, @@ -97,16 +72,12 @@ pub fn float_to_str_bytes_common( ) -> U where F: FnOnce(&str) -> U, { - assert!(2 <= radix && radix <= 36); - match exp_format { - ExpDec if radix >= DIGIT_E_RADIX // decimal exponent 'e' - => panic!("float_to_str_bytes_common: radix {} incompatible with \ - use of 'e' as decimal exponent", radix), - _ => () - } - let _0: T = Float::zero(); let _1: T = Float::one(); + let radix: u32 = 10; + let radix_f: T = cast(radix).unwrap(); + + assert!(num.is_nan() || num >= _0, "float_to_str_bytes_common: number is negative"); match num.classify() { Fp::Nan => return f("NaN"), @@ -119,41 +90,28 @@ pub fn float_to_str_bytes_common( _ => {} } - let neg = num < _0 || (negative_zero && _1 / num == Float::neg_infinity()); - // For an f64 the exponent is in the range of [-1022, 1023] for base 2, so - // we may have up to that many digits. Give ourselves some extra wiggle room - // otherwise as well. - let mut buf = [0; 1536]; + // For an f64 the (decimal) exponent is roughly in the range of [-307, 308], so + // we may have up to that many digits. We err on the side of caution and + // add 50% extra wiggle room. + let mut buf = [0; 462]; let mut end = 0; - let radix_gen: T = cast(radix as isize).unwrap(); let (num, exp) = match exp_format { - ExpNone => (num, 0), - ExpDec if num == _0 => (num, 0), - ExpDec => { - let (exp, exp_base) = match exp_format { - ExpDec => (num.abs().log10().floor(), cast::(10.0f64).unwrap()), - ExpNone => panic!("unreachable"), - }; - - (num / exp_base.powf(exp), cast::(exp).unwrap()) + ExpDec if num != _0 => { + let exp = num.log10().floor(); + (num / radix_f.powf(exp), cast::(exp).unwrap()) } + _ => (num, 0) }; // First emit the non-fractional part, looping at least once to make // sure at least a `0` gets emitted. let mut deccum = num.trunc(); loop { - // Calculate the absolute value of each digit instead of only - // doing it once for the whole number because a - // representable negative number doesn't necessary have an - // representable additive inverse of the same type - // (See twos complement). But we assume that for the - // numbers [-35 .. 0] we always have [0 .. 35]. - let current_digit = (deccum % radix_gen).abs(); + let current_digit = deccum % radix_f; // Decrease the deccumulator one digit at a time - deccum = deccum / radix_gen; + deccum = deccum / radix_f; deccum = deccum.trunc(); let c = char::from_digit(current_digit.to_isize().unwrap() as u32, radix); @@ -170,15 +128,6 @@ pub fn float_to_str_bytes_common( DigExact(count) => (true, count + 1, true) }; - // Decide what sign to put in front - match sign { - SignNeg if neg => { - buf[end] = b'-'; - end += 1; - } - _ => () - } - buf[..end].reverse(); // Remember start of the fractional digits. @@ -205,14 +154,11 @@ pub fn float_to_str_bytes_common( ) ) { // Shift first fractional digit into the integer part - deccum = deccum * radix_gen; + deccum = deccum * radix_f; - // Calculate the absolute value of each digit. - // See note in first loop. - let current_digit = deccum.trunc().abs(); + let current_digit = deccum.trunc(); - let c = char::from_digit(current_digit.to_isize().unwrap() as u32, - radix); + let c = char::from_digit(current_digit.to_isize().unwrap() as u32, radix); buf[end] = c.unwrap() as u8; end += 1; @@ -301,12 +247,8 @@ pub fn float_to_str_bytes_common( match exp_format { ExpNone => {}, - _ => { - buf[end] = match exp_format { - ExpDec if exp_upper => 'E', - ExpDec if !exp_upper => 'e', - _ => panic!("unreachable"), - } as u8; + ExpDec => { + buf[end] = if exp_upper { b'E' } else { b'e' }; end += 1; struct Filler<'a> { @@ -324,11 +266,7 @@ pub fn float_to_str_bytes_common( } let mut filler = Filler { buf: &mut buf, end: &mut end }; - match sign { - SignNeg => { - let _ = fmt::write(&mut filler, format_args!("{:-}", exp)); - } - } + let _ = fmt::write(&mut filler, format_args!("{:-}", exp)); } } diff --git a/src/libcore/fmt/mod.rs b/src/libcore/fmt/mod.rs index 67781b73ae2..b945e2a73e2 100644 --- a/src/libcore/fmt/mod.rs +++ b/src/libcore/fmt/mod.rs @@ -1,4 +1,4 @@ -// Copyright 2013-2014 The Rust Project Developers. See the COPYRIGHT +// Copyright 2013-2015 The Rust Project Developers. See the COPYRIGHT // file at the top-level directory of this distribution and at // http://rust-lang.org/COPYRIGHT. // @@ -18,6 +18,7 @@ use clone::Clone; use iter::Iterator; use marker::{Copy, PhantomData, Sized}; use mem; +use num::Float; use option::Option; use option::Option::{Some, None}; use result::Result::Ok; @@ -904,33 +905,38 @@ impl<'a, T> Pointer for &'a mut T { } } +// Common code of floating point Debug and Display. +fn float_to_str_common(num: &T, precision: Option, post: F) -> Result + where F : FnOnce(&str) -> Result { + let digits = match precision { + Some(i) => float::DigExact(i), + None => float::DigMax(6), + }; + float::float_to_str_bytes_common(num.abs(), + digits, + float::ExpNone, + false, + post) +} + macro_rules! floating { ($ty:ident) => { #[stable(feature = "rust1", since = "1.0.0")] impl Debug for $ty { fn fmt(&self, fmt: &mut Formatter) -> Result { - Display::fmt(self, fmt) + float_to_str_common(self, fmt.precision, |absolute| { + // is_positive() counts -0.0 as negative + fmt.pad_integral(self.is_nan() || self.is_positive(), "", absolute) + }) } } #[stable(feature = "rust1", since = "1.0.0")] impl Display for $ty { fn fmt(&self, fmt: &mut Formatter) -> Result { - use num::Float; - - let digits = match fmt.precision { - Some(i) => float::DigExact(i), - None => float::DigMax(6), - }; - float::float_to_str_bytes_common(self.abs(), - 10, - true, - float::SignNeg, - digits, - float::ExpNone, - false, - |bytes| { - fmt.pad_integral(self.is_nan() || *self >= 0.0, "", bytes) + float_to_str_common(self, fmt.precision, |absolute| { + // simple comparison counts -0.0 as positive + fmt.pad_integral(self.is_nan() || *self >= 0.0, "", absolute) }) } } @@ -945,9 +951,6 @@ macro_rules! floating { ($ty:ident) => { None => float::DigMax(6), }; float::float_to_str_bytes_common(self.abs(), - 10, - true, - float::SignNeg, digits, float::ExpDec, false, @@ -967,9 +970,6 @@ macro_rules! floating { ($ty:ident) => { None => float::DigMax(6), }; float::float_to_str_bytes_common(self.abs(), - 10, - true, - float::SignNeg, digits, float::ExpDec, true, diff --git a/src/test/run-pass/ifmt.rs b/src/test/run-pass/ifmt.rs index 3a7af097644..ea9db9b1e1f 100644 --- a/src/test/run-pass/ifmt.rs +++ b/src/test/run-pass/ifmt.rs @@ -1,4 +1,4 @@ -// Copyright 2014 The Rust Project Developers. See the COPYRIGHT +// Copyright 2014-2015 The Rust Project Developers. See the COPYRIGHT // file at the top-level directory of this distribution and at // http://rust-lang.org/COPYRIGHT. // @@ -144,6 +144,12 @@ pub fn main() { t!(format!("{:+10.3e}", 1.2345e6f64), " +1.234e6"); t!(format!("{:+10.3e}", -1.2345e6f64), " -1.234e6"); + // Float edge cases + t!(format!("{}", -0.0), "0"); + t!(format!("{:?}", -0.0), "-0"); + t!(format!("{:?}", 0.0), "0"); + + // Test that pointers don't get truncated. { let val = usize::MAX; -- cgit 1.4.1-3-g733a5 From 6fa16d6a473415415cb87a1fe6754aace32cbb1c Mon Sep 17 00:00:00 2001 From: Andrew Paseltiner Date: Mon, 13 Apr 2015 10:21:32 -0400 Subject: pluralize doc comment verbs and add missing periods --- src/libcollections/bit.rs | 4 +- src/libcollections/btree/map.rs | 4 +- src/libcollections/btree/set.rs | 4 +- src/libcollections/slice.rs | 6 +-- src/libcollections/str.rs | 8 ++-- src/libcollections/string.rs | 14 +++--- src/libcollections/vec.rs | 6 +-- src/libcollections/vec_deque.rs | 2 +- src/libcollections/vec_map.rs | 4 +- src/libcore/any.rs | 2 +- src/libcore/cell.rs | 10 ++-- src/libcore/clone.rs | 14 +++--- src/libcore/intrinsics.rs | 18 ++++---- src/libcore/iter.rs | 48 +++++++++---------- src/libcore/mem.rs | 8 ++-- src/libcore/nonzero.rs | 2 +- src/libcore/num/mod.rs | 86 +++++++++++++++++------------------ src/libcore/option.rs | 8 ++-- src/libcore/ptr.rs | 6 +-- src/libcore/result.rs | 16 +++---- src/libcore/str/pattern.rs | 8 ++-- src/libstd/ascii.rs | 12 ++--- src/libstd/collections/hash/map.rs | 6 +-- src/libstd/collections/hash/set.rs | 10 ++-- src/libstd/dynamic_lib.rs | 2 +- src/libstd/env.rs | 2 +- src/libstd/ffi/c_str.rs | 12 ++--- src/libstd/ffi/mod.rs | 2 +- src/libstd/ffi/os_str.rs | 24 +++++----- src/libstd/fs.rs | 26 +++++------ src/libstd/io/cursor.rs | 8 ++-- src/libstd/io/error.rs | 2 +- src/libstd/io/mod.rs | 12 ++--- src/libstd/io/stdio.rs | 14 +++--- src/libstd/net/ip.rs | 12 ++--- src/libstd/net/tcp.rs | 8 ++-- src/libstd/net/udp.rs | 4 +- src/libstd/num/f32.rs | 20 ++++---- src/libstd/num/f64.rs | 20 ++++---- src/libstd/num/mod.rs | 20 ++++---- src/libstd/path.rs | 32 ++++++------- src/libstd/process.rs | 8 ++-- src/libstd/sync/barrier.rs | 6 +-- src/libstd/sync/condvar.rs | 22 ++++----- src/libstd/sync/mpsc/mod.rs | 2 +- src/libstd/sync/mpsc/select.rs | 4 +- src/libstd/sync/mutex.rs | 2 +- src/libstd/sync/once.rs | 2 +- src/libstd/sync/rwlock.rs | 16 +++---- src/libstd/sys/common/condvar.rs | 10 ++-- src/libstd/sys/common/mutex.rs | 8 ++-- src/libstd/sys/common/poison.rs | 2 +- src/libstd/sys/common/rwlock.rs | 14 +++--- src/libstd/sys/common/thread_local.rs | 2 +- src/libstd/sys/common/wtf8.rs | 54 +++++++++++----------- src/libstd/sys/unix/ext.rs | 10 ++-- src/libstd/sys/unix/fd.rs | 2 +- src/libstd/sys/unix/fs.rs | 2 +- src/libstd/sys/unix/mod.rs | 2 +- src/libstd/sys/unix/os.rs | 2 +- src/libstd/sys/windows/ext.rs | 18 ++++---- src/libstd/sys/windows/mod.rs | 2 +- src/libstd/sys/windows/os.rs | 2 +- src/libstd/thread/local.rs | 2 +- src/libstd/thread/mod.rs | 36 +++++++-------- src/libstd/thread/scoped_tls.rs | 4 +- 66 files changed, 380 insertions(+), 380 deletions(-) (limited to 'src/libcore') diff --git a/src/libcollections/bit.rs b/src/libcollections/bit.rs index d9255241af0..d12b979e084 100644 --- a/src/libcollections/bit.rs +++ b/src/libcollections/bit.rs @@ -923,7 +923,7 @@ impl BitVec { self.set(insert_pos, elem); } - /// Return the total number of bits in this vector + /// Returns the total number of bits in this vector #[inline] #[stable(feature = "rust1", since = "1.0.0")] pub fn len(&self) -> usize { self.nbits } @@ -1695,7 +1695,7 @@ impl BitSet { self.other_op(other, |w1, w2| w1 ^ w2); } - /// Return the number of set bits in this set. + /// Returns the number of set bits in this set. #[inline] #[stable(feature = "rust1", since = "1.0.0")] pub fn len(&self) -> usize { diff --git a/src/libcollections/btree/map.rs b/src/libcollections/btree/map.rs index e704a956492..413100039a2 100644 --- a/src/libcollections/btree/map.rs +++ b/src/libcollections/btree/map.rs @@ -1339,7 +1339,7 @@ impl BTreeMap { Values { inner: self.iter().map(second) } } - /// Return the number of elements in the map. + /// Returns the number of elements in the map. /// /// # Examples /// @@ -1354,7 +1354,7 @@ impl BTreeMap { #[stable(feature = "rust1", since = "1.0.0")] pub fn len(&self) -> usize { self.length } - /// Return true if the map contains no elements. + /// Returns true if the map contains no elements. /// /// # Examples /// diff --git a/src/libcollections/btree/set.rs b/src/libcollections/btree/set.rs index 840110b5b27..1abd56fd145 100644 --- a/src/libcollections/btree/set.rs +++ b/src/libcollections/btree/set.rs @@ -284,7 +284,7 @@ impl BTreeSet { Union{a: self.iter().peekable(), b: other.iter().peekable()} } - /// Return the number of elements in the set + /// Returns the number of elements in the set. /// /// # Examples /// @@ -299,7 +299,7 @@ impl BTreeSet { #[stable(feature = "rust1", since = "1.0.0")] pub fn len(&self) -> usize { self.map.len() } - /// Returns true if the set contains no elements + /// Returns true if the set contains no elements. /// /// # Examples /// diff --git a/src/libcollections/slice.rs b/src/libcollections/slice.rs index 8622b8cd935..5be9739cb32 100644 --- a/src/libcollections/slice.rs +++ b/src/libcollections/slice.rs @@ -549,7 +549,7 @@ impl [T] { core_slice::SliceExt::binary_search_by(self, f) } - /// Return the number of elements in the slice + /// Returns the number of elements in the slice. /// /// # Example /// @@ -757,7 +757,7 @@ impl [T] { core_slice::SliceExt::get_unchecked_mut(self, index) } - /// Return an unsafe mutable pointer to the slice's buffer. + /// Returns an unsafe mutable pointer to the slice's buffer. /// /// The caller must ensure that the slice outlives the pointer this /// function returns, or else it will end up pointing to garbage. @@ -984,7 +984,7 @@ impl [T] { core_slice::SliceExt::ends_with(self, needle) } - /// Convert `self` into a vector without clones or allocation. + /// Converts `self` into a vector without clones or allocation. #[stable(feature = "rust1", since = "1.0.0")] #[inline] pub fn into_vec(self: Box) -> Vec { diff --git a/src/libcollections/str.rs b/src/libcollections/str.rs index 98f2933effc..e1da8b3b3bc 100644 --- a/src/libcollections/str.rs +++ b/src/libcollections/str.rs @@ -1248,7 +1248,7 @@ impl str { core_str::StrExt::trim_right_matches(&self[..], pat) } - /// Check that `index`-th byte lies at the start and/or end of a + /// Checks that `index`-th byte lies at the start and/or end of a /// UTF-8 code point sequence. /// /// The start and end of the string (when `index == self.len()`) are @@ -1435,7 +1435,7 @@ impl str { core_str::StrExt::char_at_reverse(&self[..], i) } - /// Convert `self` to a byte slice. + /// Converts `self` to a byte slice. /// /// # Examples /// @@ -1591,7 +1591,7 @@ impl str { core_str::StrExt::subslice_offset(&self[..], inner) } - /// Return an unsafe pointer to the `&str`'s buffer. + /// Returns an unsafe pointer to the `&str`'s buffer. /// /// The caller must ensure that the string outlives this pointer, and /// that it is not @@ -1609,7 +1609,7 @@ impl str { core_str::StrExt::as_ptr(&self[..]) } - /// Return an iterator of `u16` over the string encoded as UTF-16. + /// Returns an iterator of `u16` over the string encoded as UTF-16. #[unstable(feature = "collections", reason = "this functionality may only be provided by libunicode")] pub fn utf16_units(&self) -> Utf16Units { diff --git a/src/libcollections/string.rs b/src/libcollections/string.rs index 441d0f2c5df..c3266ea2948 100644 --- a/src/libcollections/string.rs +++ b/src/libcollections/string.rs @@ -347,7 +347,7 @@ impl String { String { vec: bytes } } - /// Return the underlying byte buffer, encoded as UTF-8. + /// Returns the underlying byte buffer, encoded as UTF-8. /// /// # Examples /// @@ -363,7 +363,7 @@ impl String { self.vec } - /// Extract a string slice containing the entire string. + /// Extracts a string slice containing the entire string. #[inline] #[unstable(feature = "convert", reason = "waiting on RFC revision")] @@ -607,7 +607,7 @@ impl String { ch } - /// Insert a character into the string buffer at byte position `idx`. + /// Inserts a character into the string buffer at byte position `idx`. /// /// # Warning /// @@ -662,7 +662,7 @@ impl String { &mut self.vec } - /// Return the number of bytes in this string. + /// Returns the number of bytes in this string. /// /// # Examples /// @@ -705,12 +705,12 @@ impl String { } impl FromUtf8Error { - /// Consume this error, returning the bytes that were attempted to make a + /// Consumes this error, returning the bytes that were attempted to make a /// `String` with. #[stable(feature = "rust1", since = "1.0.0")] pub fn into_bytes(self) -> Vec { self.bytes } - /// Access the underlying UTF8-error that was the cause of this error. + /// Accesss the underlying UTF8-error that was the cause of this error. #[stable(feature = "rust1", since = "1.0.0")] pub fn utf8_error(&self) -> Utf8Error { self.error } } @@ -959,7 +959,7 @@ impl<'a> Deref for DerefString<'a> { } } -/// Convert a string slice to a wrapper type providing a `&String` reference. +/// Converts a string slice to a wrapper type providing a `&String` reference. /// /// # Examples /// diff --git a/src/libcollections/vec.rs b/src/libcollections/vec.rs index 240a55181de..4fa91a6a16a 100644 --- a/src/libcollections/vec.rs +++ b/src/libcollections/vec.rs @@ -393,7 +393,7 @@ impl Vec { } } - /// Convert the vector into Box<[T]>. + /// Converts the vector into Box<[T]>. /// /// Note that this will drop any excess capacity. Calling this and /// converting back to a vector with `into_vec()` is equivalent to calling @@ -434,7 +434,7 @@ impl Vec { } } - /// Extract a slice containing the entire vector. + /// Extracts a slice containing the entire vector. #[inline] #[unstable(feature = "convert", reason = "waiting on RFC revision")] @@ -1936,7 +1936,7 @@ impl<'a, T> Drop for DerefVec<'a, T> { } } -/// Convert a slice to a wrapper type providing a `&Vec` reference. +/// Converts a slice to a wrapper type providing a `&Vec` reference. #[unstable(feature = "collections")] pub fn as_vec<'a, T>(x: &'a [T]) -> DerefVec<'a, T> { unsafe { diff --git a/src/libcollections/vec_deque.rs b/src/libcollections/vec_deque.rs index 49b0c229215..a66cde81c8b 100644 --- a/src/libcollections/vec_deque.rs +++ b/src/libcollections/vec_deque.rs @@ -481,7 +481,7 @@ impl VecDeque { } } - /// Shorten a ringbuf, dropping excess elements from the back. + /// Shortens a ringbuf, dropping excess elements from the back. /// /// If `len` is greater than the ringbuf's current length, this has no /// effect. diff --git a/src/libcollections/vec_map.rs b/src/libcollections/vec_map.rs index 3d9d8cf51ec..cb86e4ab38d 100644 --- a/src/libcollections/vec_map.rs +++ b/src/libcollections/vec_map.rs @@ -452,7 +452,7 @@ impl VecMap { Drain { iter: self.v.drain().enumerate().filter_map(filter) } } - /// Return the number of elements in the map. + /// Returns the number of elements in the map. /// /// # Examples /// @@ -470,7 +470,7 @@ impl VecMap { self.v.iter().filter(|elt| elt.is_some()).count() } - /// Return true if the map contains no elements. + /// Returns true if the map contains no elements. /// /// # Examples /// diff --git a/src/libcore/any.rs b/src/libcore/any.rs index 7025c76d92c..85b8accadf3 100644 --- a/src/libcore/any.rs +++ b/src/libcore/any.rs @@ -91,7 +91,7 @@ use marker::{Reflect, Sized}; /// [mod]: index.html #[stable(feature = "rust1", since = "1.0.0")] pub trait Any: Reflect + 'static { - /// Get the `TypeId` of `self` + /// Gets the `TypeId` of `self`. #[unstable(feature = "core", reason = "this method will likely be replaced by an associated static")] fn get_type_id(&self) -> TypeId; diff --git a/src/libcore/cell.rs b/src/libcore/cell.rs index 76e09eedbdf..df0de234b9a 100644 --- a/src/libcore/cell.rs +++ b/src/libcore/cell.rs @@ -211,7 +211,7 @@ impl Cell { } } - /// Get a reference to the underlying `UnsafeCell`. + /// Gets a reference to the underlying `UnsafeCell`. /// /// # Unsafety /// @@ -436,7 +436,7 @@ impl RefCell { } } - /// Get a reference to the underlying `UnsafeCell`. + /// Gets a reference to the underlying `UnsafeCell`. /// /// This can be used to circumvent `RefCell`'s safety checks. /// @@ -537,7 +537,7 @@ impl<'b, T> Deref for Ref<'b, T> { } } -/// Copy a `Ref`. +/// Copies a `Ref`. /// /// The `RefCell` is already immutably borrowed, so this cannot fail. /// @@ -647,7 +647,7 @@ pub struct UnsafeCell { impl !Sync for UnsafeCell {} impl UnsafeCell { - /// Construct a new instance of `UnsafeCell` which will wrap the specified + /// Constructs a new instance of `UnsafeCell` which will wrap the specified /// value. /// /// All access to the inner value through methods is `unsafe`, and it is highly discouraged to @@ -685,7 +685,7 @@ impl UnsafeCell { &self.value as *const T as *mut T } - /// Unwraps the value + /// Unwraps the value. /// /// # Unsafety /// diff --git a/src/libcore/clone.rs b/src/libcore/clone.rs index 311901b43d4..f11c01507dc 100644 --- a/src/libcore/clone.rs +++ b/src/libcore/clone.rs @@ -38,7 +38,7 @@ pub trait Clone : Sized { #[stable(feature = "rust1", since = "1.0.0")] fn clone(&self) -> Self; - /// Perform copy-assignment from `source`. + /// Performs copy-assignment from `source`. /// /// `a.clone_from(&b)` is equivalent to `a = b.clone()` in functionality, /// but can be overridden to reuse the resources of `a` to avoid unnecessary @@ -52,7 +52,7 @@ pub trait Clone : Sized { #[stable(feature = "rust1", since = "1.0.0")] impl<'a, T: ?Sized> Clone for &'a T { - /// Return a shallow copy of the reference. + /// Returns a shallow copy of the reference. #[inline] fn clone(&self) -> &'a T { *self } } @@ -61,7 +61,7 @@ macro_rules! clone_impl { ($t:ty) => { #[stable(feature = "rust1", since = "1.0.0")] impl Clone for $t { - /// Return a deep copy of the value. + /// Returns a deep copy of the value. #[inline] fn clone(&self) -> $t { *self } } @@ -92,28 +92,28 @@ macro_rules! extern_fn_clone { #[unstable(feature = "core", reason = "this may not be sufficient for fns with region parameters")] impl<$($A,)* ReturnType> Clone for extern "Rust" fn($($A),*) -> ReturnType { - /// Return a copy of a function pointer + /// Returns a copy of a function pointer. #[inline] fn clone(&self) -> extern "Rust" fn($($A),*) -> ReturnType { *self } } #[unstable(feature = "core", reason = "brand new")] impl<$($A,)* ReturnType> Clone for extern "C" fn($($A),*) -> ReturnType { - /// Return a copy of a function pointer + /// Returns a copy of a function pointer. #[inline] fn clone(&self) -> extern "C" fn($($A),*) -> ReturnType { *self } } #[unstable(feature = "core", reason = "brand new")] impl<$($A,)* ReturnType> Clone for unsafe extern "Rust" fn($($A),*) -> ReturnType { - /// Return a copy of a function pointer + /// Returns a copy of a function pointer. #[inline] fn clone(&self) -> unsafe extern "Rust" fn($($A),*) -> ReturnType { *self } } #[unstable(feature = "core", reason = "brand new")] impl<$($A,)* ReturnType> Clone for unsafe extern "C" fn($($A),*) -> ReturnType { - /// Return a copy of a function pointer + /// Returns a copy of a function pointer. #[inline] fn clone(&self) -> unsafe extern "C" fn($($A),*) -> ReturnType { *self } } diff --git a/src/libcore/intrinsics.rs b/src/libcore/intrinsics.rs index 80f506ebc06..8ed89adec5b 100644 --- a/src/libcore/intrinsics.rs +++ b/src/libcore/intrinsics.rs @@ -139,16 +139,16 @@ extern "rust-intrinsic" { pub fn atomic_fence_rel(); pub fn atomic_fence_acqrel(); - /// Abort the execution of the process. + /// Aborts the execution of the process. pub fn abort() -> !; - /// Tell LLVM that this point in the code is not reachable, + /// Tells LLVM that this point in the code is not reachable, /// enabling further optimizations. /// /// NB: This is very different from the `unreachable!()` macro! pub fn unreachable() -> !; - /// Inform the optimizer that a condition is always true. + /// Informs the optimizer that a condition is always true. /// If the condition is false, the behavior is undefined. /// /// No code is generated for this intrinsic, but the optimizer will try @@ -158,7 +158,7 @@ extern "rust-intrinsic" { /// own, or if it does not enable any significant optimizations. pub fn assume(b: bool); - /// Execute a breakpoint trap, for inspection by a debugger. + /// Executes a breakpoint trap, for inspection by a debugger. pub fn breakpoint(); /// The size of a type in bytes. @@ -170,7 +170,7 @@ extern "rust-intrinsic" { /// elements. pub fn size_of() -> usize; - /// Move a value to an uninitialized memory location. + /// Moves a value to an uninitialized memory location. /// /// Drop glue is not run on the destination. pub fn move_val_init(dst: &mut T, src: T); @@ -186,7 +186,7 @@ extern "rust-intrinsic" { /// crate it is invoked in. pub fn type_id() -> u64; - /// Create a value initialized to so that its drop flag, + /// Creates a value initialized to so that its drop flag, /// if any, says that it has been dropped. /// /// `init_dropped` is unsafe because it returns a datum with all @@ -199,7 +199,7 @@ extern "rust-intrinsic" { /// intrinsic). pub fn init_dropped() -> T; - /// Create a value initialized to zero. + /// Creates a value initialized to zero. /// /// `init` is unsafe because it returns a zeroed-out datum, /// which is unsafe unless T is `Copy`. Also, even if T is @@ -207,7 +207,7 @@ extern "rust-intrinsic" { /// state for the type in question. pub fn init() -> T; - /// Create an uninitialized value. + /// Creates an uninitialized value. /// /// `uninit` is unsafe because there is no guarantee of what its /// contents are. In particular its drop-flag may be set to any @@ -216,7 +216,7 @@ extern "rust-intrinsic" { /// initialize memory previous set to the result of `uninit`. pub fn uninit() -> T; - /// Move a value out of scope without running drop glue. + /// Moves a value out of scope without running drop glue. /// /// `forget` is unsafe because the caller is responsible for /// ensuring the argument is deallocated already. diff --git a/src/libcore/iter.rs b/src/libcore/iter.rs index 9f378748d20..81a5a676e1a 100644 --- a/src/libcore/iter.rs +++ b/src/libcore/iter.rs @@ -91,7 +91,7 @@ pub trait Iterator { #[stable(feature = "rust1", since = "1.0.0")] type Item; - /// Advance the iterator and return the next value. Return `None` when the + /// Advances the iterator and returns the next value. Returns `None` when the /// end is reached. #[stable(feature = "rust1", since = "1.0.0")] fn next(&mut self) -> Option; @@ -670,7 +670,7 @@ pub trait Iterator { None } - /// Return the index of the first element satisfying the specified predicate + /// Returns the index of the first element satisfying the specified predicate /// /// Does not consume the iterator past the first found element. /// @@ -698,7 +698,7 @@ pub trait Iterator { None } - /// Return the index of the last element satisfying the specified predicate + /// Returns the index of the last element satisfying the specified predicate /// /// If no element matches, None is returned. /// @@ -853,7 +853,7 @@ pub trait Iterator { MinMax(min, max) } - /// Return the element that gives the maximum value from the + /// Returns the element that gives the maximum value from the /// specified function. /// /// Returns the rightmost element if the comparison determines two elements @@ -882,7 +882,7 @@ pub trait Iterator { .map(|(_, x)| x) } - /// Return the element that gives the minimum value from the + /// Returns the element that gives the minimum value from the /// specified function. /// /// Returns the leftmost element if the comparison determines two elements @@ -1099,7 +1099,7 @@ impl<'a, I: Iterator + ?Sized> Iterator for &'a mut I { #[rustc_on_unimplemented="a collection of type `{Self}` cannot be \ built from an iterator over elements of type `{A}`"] pub trait FromIterator { - /// Build a container with elements from something iterable. + /// Builds a container with elements from something iterable. /// /// # Examples /// @@ -1158,7 +1158,7 @@ impl IntoIterator for I { /// A type growable from an `Iterator` implementation #[stable(feature = "rust1", since = "1.0.0")] pub trait Extend { - /// Extend a container with the elements yielded by an arbitrary iterator + /// Extends a container with the elements yielded by an arbitrary iterator #[stable(feature = "rust1", since = "1.0.0")] fn extend>(&mut self, iterable: T); } @@ -1170,7 +1170,7 @@ pub trait Extend { /// independently of each other. #[stable(feature = "rust1", since = "1.0.0")] pub trait DoubleEndedIterator: Iterator { - /// Yield an element from the end of the range, returning `None` if the + /// Yields an element from the end of the range, returning `None` if the /// range is empty. #[stable(feature = "rust1", since = "1.0.0")] fn next_back(&mut self) -> Option; @@ -1191,11 +1191,11 @@ impl<'a, I: DoubleEndedIterator + ?Sized> DoubleEndedIterator for &'a mut I { reason = "not widely used, may be better decomposed into Index \ and ExactSizeIterator")] pub trait RandomAccessIterator: Iterator { - /// Return the number of indexable elements. At most `std::usize::MAX` + /// Returns the number of indexable elements. At most `std::usize::MAX` /// elements are indexable, even if the iterator represents a longer range. fn indexable(&self) -> usize; - /// Return an element at an index, or `None` if the index is out of bounds + /// Returns an element at an index, or `None` if the index is out of bounds fn idx(&mut self, index: usize) -> Option; } @@ -1210,7 +1210,7 @@ pub trait RandomAccessIterator: Iterator { pub trait ExactSizeIterator: Iterator { #[inline] #[stable(feature = "rust1", since = "1.0.0")] - /// Return the exact length of the iterator. + /// Returns the exact length of the iterator. fn len(&self) -> usize { let (lower, upper) = self.size_hint(); // Note: This assertion is overly defensive, but it checks the invariant @@ -1856,7 +1856,7 @@ impl ExactSizeIterator for Peekable {} #[stable(feature = "rust1", since = "1.0.0")] impl Peekable { - /// Return a reference to the next element of the iterator with out + /// Returns a reference to the next element of the iterator with out /// advancing it, or None if the iterator is exhausted. #[inline] #[stable(feature = "rust1", since = "1.0.0")] @@ -1870,7 +1870,7 @@ impl Peekable { } } - /// Check whether peekable iterator is empty or not. + /// Checks whether peekable iterator is empty or not. #[inline] pub fn is_empty(&mut self) -> bool { self.peek().is_none() @@ -2401,12 +2401,12 @@ pub trait Step: PartialOrd { /// Steps `self` if possible. fn step(&self, by: &Self) -> Option; - /// The number of steps between two step objects. + /// Returns the number of steps between two step objects. /// /// `start` should always be less than `end`, so the result should never /// be negative. /// - /// Return `None` if it is not possible to calculate steps_between + /// Returns `None` if it is not possible to calculate steps_between /// without overflow. fn steps_between(start: &Self, end: &Self, by: &Self) -> Option; } @@ -2549,7 +2549,7 @@ pub struct RangeInclusive { done: bool, } -/// Return an iterator over the range [start, stop] +/// Returns an iterator over the range [start, stop]. #[inline] #[unstable(feature = "core", reason = "likely to be replaced by range notation and adapters")] @@ -2657,7 +2657,7 @@ pub struct RangeStepInclusive { done: bool, } -/// Return an iterator over the range [start, stop] by `step`. +/// Returns an iterator over the range [start, stop] by `step`. /// /// It handles overflow by stopping. /// @@ -2827,7 +2827,7 @@ type IterateState = (F, Option, bool); #[unstable(feature = "core")] pub type Iterate = Unfold, fn(&mut IterateState) -> Option>; -/// Create a new iterator that produces an infinite sequence of +/// Creates a new iterator that produces an infinite sequence of /// repeated applications of the given function `f`. #[unstable(feature = "core")] pub fn iterate(seed: T, f: F) -> Iterate where @@ -2853,7 +2853,7 @@ pub fn iterate(seed: T, f: F) -> Iterate where Unfold::new((f, Some(seed), true), next) } -/// Create a new iterator that endlessly repeats the element `elt`. +/// Creates a new iterator that endlessly repeats the element `elt`. #[inline] #[stable(feature = "rust1", since = "1.0.0")] pub fn repeat(elt: T) -> Repeat { @@ -2940,7 +2940,7 @@ pub mod order { } } - /// Compare `a` and `b` for nonequality (Using partial equality, `PartialEq`) + /// Compares `a` and `b` for nonequality (Using partial equality, `PartialEq`) pub fn ne(mut a: L, mut b: R) -> bool where L::Item: PartialEq, { @@ -2953,7 +2953,7 @@ pub mod order { } } - /// Return `a` < `b` lexicographically (Using partial order, `PartialOrd`) + /// Returns `a` < `b` lexicographically (Using partial order, `PartialOrd`) pub fn lt(mut a: L, mut b: R) -> bool where L::Item: PartialOrd, { @@ -2967,7 +2967,7 @@ pub mod order { } } - /// Return `a` <= `b` lexicographically (Using partial order, `PartialOrd`) + /// Returns `a` <= `b` lexicographically (Using partial order, `PartialOrd`) pub fn le(mut a: L, mut b: R) -> bool where L::Item: PartialOrd, { @@ -2981,7 +2981,7 @@ pub mod order { } } - /// Return `a` > `b` lexicographically (Using partial order, `PartialOrd`) + /// Returns `a` > `b` lexicographically (Using partial order, `PartialOrd`) pub fn gt(mut a: L, mut b: R) -> bool where L::Item: PartialOrd, { @@ -2995,7 +2995,7 @@ pub mod order { } } - /// Return `a` >= `b` lexicographically (Using partial order, `PartialOrd`) + /// Returns `a` >= `b` lexicographically (Using partial order, `PartialOrd`) pub fn ge(mut a: L, mut b: R) -> bool where L::Item: PartialOrd, { diff --git a/src/libcore/mem.rs b/src/libcore/mem.rs index 249beb6295c..c4128e79765 100644 --- a/src/libcore/mem.rs +++ b/src/libcore/mem.rs @@ -134,7 +134,7 @@ pub fn align_of_val(_val: &T) -> usize { align_of::() } -/// Create a value initialized to zero. +/// Creates a value initialized to zero. /// /// This function is similar to allocating space for a local variable and zeroing it out (an unsafe /// operation). @@ -158,7 +158,7 @@ pub unsafe fn zeroed() -> T { intrinsics::init() } -/// Create a value initialized to an unspecified series of bytes. +/// Creates a value initialized to an unspecified series of bytes. /// /// The byte sequence usually indicates that the value at the memory /// in question has been dropped. Thus, *if* T carries a drop flag, @@ -179,7 +179,7 @@ pub unsafe fn dropped() -> T { dropped_impl() } -/// Create an uninitialized value. +/// Creates an uninitialized value. /// /// Care must be taken when using this function, if the type `T` has a destructor and the value /// falls out of scope (due to unwinding or returning) before being initialized, then the @@ -234,7 +234,7 @@ pub fn swap(x: &mut T, y: &mut T) { } } -/// Replace the value at a mutable location with a new one, returning the old value, without +/// Replaces the value at a mutable location with a new one, returning the old value, without /// deinitialising or copying either one. /// /// This is primarily used for transferring and swapping ownership of a value in a mutable diff --git a/src/libcore/nonzero.rs b/src/libcore/nonzero.rs index 3df4d00f60c..db2d1b2f1fd 100644 --- a/src/libcore/nonzero.rs +++ b/src/libcore/nonzero.rs @@ -38,7 +38,7 @@ unsafe impl Zeroable for u64 {} pub struct NonZero(T); impl NonZero { - /// Create an instance of NonZero with the provided value. + /// Creates an instance of NonZero with the provided value. /// You must indeed ensure that the value is actually "non-zero". #[inline(always)] pub unsafe fn new(inner: T) -> NonZero { diff --git a/src/libcore/num/mod.rs b/src/libcore/num/mod.rs index 3fd179cf86f..9b1a384a0d0 100644 --- a/src/libcore/num/mod.rs +++ b/src/libcore/num/mod.rs @@ -268,7 +268,7 @@ pub trait Int #[stable(feature = "rust1", since = "1.0.0")] fn swap_bytes(self) -> Self; - /// Convert an integer from big endian to the target's endianness. + /// Converts an integer from big endian to the target's endianness. /// /// On big endian this is a no-op. On little endian the bytes are swapped. /// @@ -291,7 +291,7 @@ pub trait Int if cfg!(target_endian = "big") { x } else { x.swap_bytes() } } - /// Convert an integer from little endian to the target's endianness. + /// Converts an integer from little endian to the target's endianness. /// /// On little endian this is a no-op. On big endian the bytes are swapped. /// @@ -314,7 +314,7 @@ pub trait Int if cfg!(target_endian = "little") { x } else { x.swap_bytes() } } - /// Convert `self` to big endian from the target's endianness. + /// Converts `self` to big endian from the target's endianness. /// /// On big endian this is a no-op. On little endian the bytes are swapped. /// @@ -337,7 +337,7 @@ pub trait Int if cfg!(target_endian = "big") { self } else { self.swap_bytes() } } - /// Convert `self` to little endian from the target's endianness. + /// Converts `self` to little endian from the target's endianness. /// /// On little endian this is a no-op. On big endian the bytes are swapped. /// @@ -845,7 +845,7 @@ macro_rules! int_impl { let min: $T = Int::min_value(); !min } - /// Convert a string slice in a given base to an integer. + /// Converts a string slice in a given base to an integer. /// /// Leading and trailing whitespace represent an error. /// @@ -995,7 +995,7 @@ macro_rules! int_impl { (self as $UnsignedT).swap_bytes() as $T } - /// Convert an integer from big endian to the target's endianness. + /// Converts an integer from big endian to the target's endianness. /// /// On big endian this is a no-op. On little endian the bytes are /// swapped. @@ -1019,7 +1019,7 @@ macro_rules! int_impl { if cfg!(target_endian = "big") { x } else { x.swap_bytes() } } - /// Convert an integer from little endian to the target's endianness. + /// Converts an integer from little endian to the target's endianness. /// /// On little endian this is a no-op. On big endian the bytes are /// swapped. @@ -1043,7 +1043,7 @@ macro_rules! int_impl { if cfg!(target_endian = "little") { x } else { x.swap_bytes() } } - /// Convert `self` to big endian from the target's endianness. + /// Converts `self` to big endian from the target's endianness. /// /// On big endian this is a no-op. On little endian the bytes are /// swapped. @@ -1067,7 +1067,7 @@ macro_rules! int_impl { if cfg!(target_endian = "big") { self } else { self.swap_bytes() } } - /// Convert `self` to little endian from the target's endianness. + /// Converts `self` to little endian from the target's endianness. /// /// On little endian this is a no-op. On big endian the bytes are /// swapped. @@ -1361,7 +1361,7 @@ macro_rules! uint_impl { #[stable(feature = "rust1", since = "1.0.0")] pub fn max_value() -> $T { !0 } - /// Convert a string slice in a given base to an integer. + /// Converts a string slice in a given base to an integer. /// /// Leading and trailing whitespace represent an error. /// @@ -1517,7 +1517,7 @@ macro_rules! uint_impl { unsafe { $bswap(self as $ActualT) as $T } } - /// Convert an integer from big endian to the target's endianness. + /// Converts an integer from big endian to the target's endianness. /// /// On big endian this is a no-op. On little endian the bytes are /// swapped. @@ -1541,7 +1541,7 @@ macro_rules! uint_impl { if cfg!(target_endian = "big") { x } else { x.swap_bytes() } } - /// Convert an integer from little endian to the target's endianness. + /// Converts an integer from little endian to the target's endianness. /// /// On little endian this is a no-op. On big endian the bytes are /// swapped. @@ -1565,7 +1565,7 @@ macro_rules! uint_impl { if cfg!(target_endian = "little") { x } else { x.swap_bytes() } } - /// Convert `self` to big endian from the target's endianness. + /// Converts `self` to big endian from the target's endianness. /// /// On big endian this is a no-op. On little endian the bytes are /// swapped. @@ -1589,7 +1589,7 @@ macro_rules! uint_impl { if cfg!(target_endian = "big") { self } else { self.swap_bytes() } } - /// Convert `self` to little endian from the target's endianness. + /// Converts `self` to little endian from the target's endianness. /// /// On little endian this is a no-op. On big endian the bytes are /// swapped. @@ -2183,7 +2183,7 @@ impl_to_primitive_float! { f64 } /// A generic trait for converting a number to a value. #[unstable(feature = "core", reason = "trait is likely to be removed")] pub trait FromPrimitive : ::marker::Sized { - /// Convert an `isize` to return an optional value of this type. If the + /// Converts an `isize` to return an optional value of this type. If the /// value cannot be represented by this value, the `None` is returned. #[inline] #[unstable(feature = "core")] @@ -2192,39 +2192,39 @@ pub trait FromPrimitive : ::marker::Sized { FromPrimitive::from_i64(n as i64) } - /// Convert an `isize` to return an optional value of this type. If the + /// Converts an `isize` to return an optional value of this type. If the /// value cannot be represented by this value, the `None` is returned. #[inline] fn from_isize(n: isize) -> Option { FromPrimitive::from_i64(n as i64) } - /// Convert an `i8` to return an optional value of this type. If the + /// Converts an `i8` to return an optional value of this type. If the /// type cannot be represented by this value, the `None` is returned. #[inline] fn from_i8(n: i8) -> Option { FromPrimitive::from_i64(n as i64) } - /// Convert an `i16` to return an optional value of this type. If the + /// Converts an `i16` to return an optional value of this type. If the /// type cannot be represented by this value, the `None` is returned. #[inline] fn from_i16(n: i16) -> Option { FromPrimitive::from_i64(n as i64) } - /// Convert an `i32` to return an optional value of this type. If the + /// Converts an `i32` to return an optional value of this type. If the /// type cannot be represented by this value, the `None` is returned. #[inline] fn from_i32(n: i32) -> Option { FromPrimitive::from_i64(n as i64) } - /// Convert an `i64` to return an optional value of this type. If the + /// Converts an `i64` to return an optional value of this type. If the /// type cannot be represented by this value, the `None` is returned. fn from_i64(n: i64) -> Option; - /// Convert an `usize` to return an optional value of this type. If the + /// Converts an `usize` to return an optional value of this type. If the /// type cannot be represented by this value, the `None` is returned. #[inline] #[unstable(feature = "core")] @@ -2233,46 +2233,46 @@ pub trait FromPrimitive : ::marker::Sized { FromPrimitive::from_u64(n as u64) } - /// Convert a `usize` to return an optional value of this type. If the + /// Converts a `usize` to return an optional value of this type. If the /// type cannot be represented by this value, the `None` is returned. #[inline] fn from_usize(n: usize) -> Option { FromPrimitive::from_u64(n as u64) } - /// Convert an `u8` to return an optional value of this type. If the + /// Converts an `u8` to return an optional value of this type. If the /// type cannot be represented by this value, the `None` is returned. #[inline] fn from_u8(n: u8) -> Option { FromPrimitive::from_u64(n as u64) } - /// Convert an `u16` to return an optional value of this type. If the + /// Converts an `u16` to return an optional value of this type. If the /// type cannot be represented by this value, the `None` is returned. #[inline] fn from_u16(n: u16) -> Option { FromPrimitive::from_u64(n as u64) } - /// Convert an `u32` to return an optional value of this type. If the + /// Converts an `u32` to return an optional value of this type. If the /// type cannot be represented by this value, the `None` is returned. #[inline] fn from_u32(n: u32) -> Option { FromPrimitive::from_u64(n as u64) } - /// Convert an `u64` to return an optional value of this type. If the + /// Converts an `u64` to return an optional value of this type. If the /// type cannot be represented by this value, the `None` is returned. fn from_u64(n: u64) -> Option; - /// Convert a `f32` to return an optional value of this type. If the + /// Converts a `f32` to return an optional value of this type. If the /// type cannot be represented by this value, the `None` is returned. #[inline] fn from_f32(n: f32) -> Option { FromPrimitive::from_f64(n as f64) } - /// Convert a `f64` to return an optional value of this type. If the + /// Converts a `f64` to return an optional value of this type. If the /// type cannot be represented by this value, the `None` is returned. #[inline] fn from_f64(n: f64) -> Option { @@ -2401,7 +2401,7 @@ impl_from_primitive! { u64, to_u64 } impl_from_primitive! { f32, to_f32 } impl_from_primitive! { f64, to_f64 } -/// Cast from one machine scalar to another. +/// Casts from one machine scalar to another. /// /// # Examples /// @@ -2583,16 +2583,16 @@ pub trait Float /// Returns the mantissa, exponent and sign as integers, respectively. fn integer_decode(self) -> (u64, i16, i8); - /// Return the largest integer less than or equal to a number. + /// Returns the largest integer less than or equal to a number. fn floor(self) -> Self; - /// Return the smallest integer greater than or equal to a number. + /// Returns the smallest integer greater than or equal to a number. fn ceil(self) -> Self; - /// Return the nearest integer to a number. Round half-way cases away from + /// Returns the nearest integer to a number. Round half-way cases away from /// `0.0`. fn round(self) -> Self; - /// Return the integer part of a number. + /// Returns the integer part of a number. fn trunc(self) -> Self; - /// Return the fractional part of a number. + /// Returns the fractional part of a number. fn fract(self) -> Self; /// Computes the absolute value of `self`. Returns `Float::nan()` if the @@ -2615,21 +2615,21 @@ pub trait Float /// error. This produces a more accurate result with better performance than /// a separate multiplication operation followed by an add. fn mul_add(self, a: Self, b: Self) -> Self; - /// Take the reciprocal (inverse) of a number, `1/x`. + /// Takes the reciprocal (inverse) of a number, `1/x`. fn recip(self) -> Self; - /// Raise a number to an integer power. + /// Raises a number to an integer power. /// /// Using this function is generally faster than using `powf` fn powi(self, n: i32) -> Self; - /// Raise a number to a floating point power. + /// Raises a number to a floating point power. fn powf(self, n: Self) -> Self; - /// Take the square root of a number. + /// Takes the square root of a number. /// /// Returns NaN if `self` is a negative number. fn sqrt(self) -> Self; - /// Take the reciprocal (inverse) square root of a number, `1/sqrt(x)`. + /// Takes the reciprocal (inverse) square root of a number, `1/sqrt(x)`. fn rsqrt(self) -> Self; /// Returns `e^(self)`, (the exponential function). @@ -2645,9 +2645,9 @@ pub trait Float /// Returns the base 10 logarithm of the number. fn log10(self) -> Self; - /// Convert radians to degrees. + /// Converts radians to degrees. fn to_degrees(self) -> Self; - /// Convert degrees to radians. + /// Converts degrees to radians. fn to_radians(self) -> Self; } @@ -2682,7 +2682,7 @@ macro_rules! from_str_radix_float_impl { impl FromStr for $T { type Err = ParseFloatError; - /// Convert a string in base 10 to a float. + /// Converts a string in base 10 to a float. /// Accepts an optional decimal exponent. /// /// This function accepts strings such as @@ -2719,7 +2719,7 @@ macro_rules! from_str_radix_float_impl { impl FromStrRadix for $T { type Err = ParseFloatError; - /// Convert a string in a given base to a float. + /// Converts a string in a given base to a float. /// /// Due to possible conflicts, this function does **not** accept /// the special values `inf`, `-inf`, `+inf` and `NaN`, **nor** diff --git a/src/libcore/option.rs b/src/libcore/option.rs index 6db7c9bd99d..4c784a579da 100644 --- a/src/libcore/option.rs +++ b/src/libcore/option.rs @@ -223,7 +223,7 @@ impl Option { // Adapter for working with references ///////////////////////////////////////////////////////////////////////// - /// Convert from `Option` to `Option<&T>` + /// Converts from `Option` to `Option<&T>` /// /// # Examples /// @@ -248,7 +248,7 @@ impl Option { } } - /// Convert from `Option` to `Option<&mut T>` + /// Converts from `Option` to `Option<&mut T>` /// /// # Examples /// @@ -269,7 +269,7 @@ impl Option { } } - /// Convert from `Option` to `&mut [T]` (without copying) + /// Converts from `Option` to `&mut [T]` (without copying) /// /// # Examples /// @@ -704,7 +704,7 @@ impl Option { mem::replace(self, None) } - /// Convert from `Option` to `&[T]` (without copying) + /// Converts from `Option` to `&[T]` (without copying) #[inline] #[unstable(feature = "as_slice", since = "unsure of the utility here")] pub fn as_slice<'a>(&'a self) -> &'a [T] { diff --git a/src/libcore/ptr.rs b/src/libcore/ptr.rs index a622ef78a21..9a165a2e317 100644 --- a/src/libcore/ptr.rs +++ b/src/libcore/ptr.rs @@ -544,19 +544,19 @@ unsafe impl Send for Unique { } unsafe impl Sync for Unique { } impl Unique { - /// Create a new `Unique`. + /// Creates a new `Unique`. #[unstable(feature = "unique")] pub unsafe fn new(ptr: *mut T) -> Unique { Unique { pointer: NonZero::new(ptr), _marker: PhantomData } } - /// Dereference the content. + /// Dereferences the content. #[unstable(feature = "unique")] pub unsafe fn get(&self) -> &T { &**self.pointer } - /// Mutably dereference the content. + /// Mutably dereferences the content. #[unstable(feature = "unique")] pub unsafe fn get_mut(&mut self) -> &mut T { &mut ***self diff --git a/src/libcore/result.rs b/src/libcore/result.rs index 67a5ab891f7..dcec75fc170 100644 --- a/src/libcore/result.rs +++ b/src/libcore/result.rs @@ -311,7 +311,7 @@ impl Result { // Adapter for each variant ///////////////////////////////////////////////////////////////////////// - /// Convert from `Result` to `Option` + /// Converts from `Result` to `Option` /// /// Converts `self` into an `Option`, consuming `self`, /// and discarding the error, if any. @@ -334,7 +334,7 @@ impl Result { } } - /// Convert from `Result` to `Option` + /// Converts from `Result` to `Option` /// /// Converts `self` into an `Option`, consuming `self`, /// and discarding the success value, if any. @@ -361,7 +361,7 @@ impl Result { // Adapter for working with references ///////////////////////////////////////////////////////////////////////// - /// Convert from `Result` to `Result<&T, &E>` + /// Converts from `Result` to `Result<&T, &E>` /// /// Produces a new `Result`, containing a reference /// into the original, leaving the original in place. @@ -382,7 +382,7 @@ impl Result { } } - /// Convert from `Result` to `Result<&mut T, &mut E>` + /// Converts from `Result` to `Result<&mut T, &mut E>` /// /// ``` /// fn mutate(r: &mut Result) { @@ -409,7 +409,7 @@ impl Result { } } - /// Convert from `Result` to `&[T]` (without copying) + /// Converts from `Result` to `&[T]` (without copying) #[inline] #[unstable(feature = "as_slice", since = "unsure of the utility here")] pub fn as_slice(&self) -> &[T] { @@ -423,7 +423,7 @@ impl Result { } } - /// Convert from `Result` to `&mut [T]` (without copying) + /// Converts from `Result` to `&mut [T]` (without copying) /// /// ``` /// # #![feature(core)] @@ -811,7 +811,7 @@ impl Result { reason = "use inherent method instead")] #[allow(deprecated)] impl AsSlice for Result { - /// Convert from `Result` to `&[T]` (without copying) + /// Converts from `Result` to `&[T]` (without copying) #[inline] fn as_slice<'a>(&'a self) -> &'a [T] { match *self { @@ -974,7 +974,7 @@ impl> FromIterator> for Result { // FromIterator ///////////////////////////////////////////////////////////////////////////// -/// Perform a fold operation over the result values from an iterator. +/// Performs a fold operation over the result values from an iterator. /// /// If an `Err` is encountered, it is immediately returned. /// Otherwise, the folded value is returned. diff --git a/src/libcore/str/pattern.rs b/src/libcore/str/pattern.rs index 9f701e1b031..62b693dcbe6 100644 --- a/src/libcore/str/pattern.rs +++ b/src/libcore/str/pattern.rs @@ -32,17 +32,17 @@ pub trait Pattern<'a>: Sized { /// Associated searcher for this pattern type Searcher: Searcher<'a>; - /// Construct the associated searcher from + /// Constructs the associated searcher from /// `self` and the `haystack` to search in. fn into_searcher(self, haystack: &'a str) -> Self::Searcher; - /// Check whether the pattern matches anywhere in the haystack + /// Checks whether the pattern matches anywhere in the haystack #[inline] fn is_contained_in(self, haystack: &'a str) -> bool { self.into_searcher(haystack).next_match().is_some() } - /// Check whether the pattern matches at the front of the haystack + /// Checks whether the pattern matches at the front of the haystack #[inline] fn is_prefix_of(self, haystack: &'a str) -> bool { match self.into_searcher(haystack).next() { @@ -51,7 +51,7 @@ pub trait Pattern<'a>: Sized { } } - /// Check whether the pattern matches at the back of the haystack + /// Checks whether the pattern matches at the back of the haystack #[inline] fn is_suffix_of(self, haystack: &'a str) -> bool where Self::Searcher: ReverseSearcher<'a> diff --git a/src/libstd/ascii.rs b/src/libstd/ascii.rs index 20ad71a4bf8..a2ba8c4c1ba 100644 --- a/src/libstd/ascii.rs +++ b/src/libstd/ascii.rs @@ -23,12 +23,12 @@ use mem; #[unstable(feature = "std_misc", reason = "would prefer to do this in a more general way")] pub trait OwnedAsciiExt { - /// Convert the string to ASCII upper case: + /// Converts the string to ASCII upper case: /// ASCII letters 'a' to 'z' are mapped to 'A' to 'Z', /// but non-ASCII letters are unchanged. fn into_ascii_uppercase(self) -> Self; - /// Convert the string to ASCII lower case: + /// Converts the string to ASCII lower case: /// ASCII letters 'A' to 'Z' are mapped to 'a' to 'z', /// but non-ASCII letters are unchanged. fn into_ascii_lowercase(self) -> Self; @@ -41,7 +41,7 @@ pub trait AsciiExt { #[stable(feature = "rust1", since = "1.0.0")] type Owned; - /// Check if within the ASCII range. + /// Checks if within the ASCII range. /// /// # Examples /// @@ -95,7 +95,7 @@ pub trait AsciiExt { #[stable(feature = "rust1", since = "1.0.0")] fn to_ascii_lowercase(&self) -> Self::Owned; - /// Check that two strings are an ASCII case-insensitive match. + /// Checks that two strings are an ASCII case-insensitive match. /// /// Same as `to_ascii_lowercase(a) == to_ascii_lowercase(b)`, /// but without allocating and copying temporary strings. @@ -117,7 +117,7 @@ pub trait AsciiExt { #[stable(feature = "rust1", since = "1.0.0")] fn eq_ignore_ascii_case(&self, other: &Self) -> bool; - /// Convert this type to its ASCII upper case equivalent in-place. + /// Converts this type to its ASCII upper case equivalent in-place. /// /// See `to_ascii_uppercase` for more information. /// @@ -136,7 +136,7 @@ pub trait AsciiExt { #[unstable(feature = "ascii")] fn make_ascii_uppercase(&mut self); - /// Convert this type to its ASCII lower case equivalent in-place. + /// Converts this type to its ASCII lower case equivalent in-place. /// /// See `to_ascii_lowercase` for more information. /// diff --git a/src/libstd/collections/hash/map.rs b/src/libstd/collections/hash/map.rs index 54a3a055768..e507146bcb3 100644 --- a/src/libstd/collections/hash/map.rs +++ b/src/libstd/collections/hash/map.rs @@ -506,7 +506,7 @@ impl HashMap } impl HashMap { - /// Create an empty HashMap. + /// Creates an empty HashMap. /// /// # Examples /// @@ -563,7 +563,7 @@ impl HashMap } } - /// Create an empty HashMap with space for at least `capacity` + /// Creates an empty HashMap with space for at least `capacity` /// elements, using `hasher` to hash the keys. /// /// Warning: `hasher` is normally randomly generated, and @@ -1596,7 +1596,7 @@ pub struct RandomState { #[unstable(feature = "std_misc", reason = "hashing an hash maps may be altered")] impl RandomState { - /// Construct a new `RandomState` that is initialized with random keys. + /// Constructs a new `RandomState` that is initialized with random keys. #[inline] #[allow(deprecated)] pub fn new() -> RandomState { diff --git a/src/libstd/collections/hash/set.rs b/src/libstd/collections/hash/set.rs index f897d565321..6b0546b1ee7 100644 --- a/src/libstd/collections/hash/set.rs +++ b/src/libstd/collections/hash/set.rs @@ -111,7 +111,7 @@ pub struct HashSet { } impl HashSet { - /// Create an empty HashSet. + /// Creates an empty HashSet. /// /// # Examples /// @@ -125,7 +125,7 @@ impl HashSet { HashSet::with_capacity(INITIAL_CAPACITY) } - /// Create an empty HashSet with space for at least `n` elements in + /// Creates an empty HashSet with space for at least `n` elements in /// the hash table. /// /// # Examples @@ -166,7 +166,7 @@ impl HashSet HashSet::with_capacity_and_hash_state(INITIAL_CAPACITY, hash_state) } - /// Create an empty HashSet with space for at least `capacity` + /// Creates an empty HashSet with space for at least `capacity` /// elements in the hash table, using `hasher` to hash the keys. /// /// Warning: `hasher` is normally randomly generated, and @@ -402,7 +402,7 @@ impl HashSet Union { iter: self.iter().chain(other.difference(self)) } } - /// Return the number of elements in the set + /// Returns the number of elements in the set. /// /// # Examples /// @@ -417,7 +417,7 @@ impl HashSet #[stable(feature = "rust1", since = "1.0.0")] pub fn len(&self) -> usize { self.map.len() } - /// Returns true if the set contains no elements + /// Returns true if the set contains no elements. /// /// # Examples /// diff --git a/src/libstd/dynamic_lib.rs b/src/libstd/dynamic_lib.rs index e76d5460eb0..c69df6435c4 100644 --- a/src/libstd/dynamic_lib.rs +++ b/src/libstd/dynamic_lib.rs @@ -105,7 +105,7 @@ impl DynamicLibrary { } } - /// Access the value at the symbol of the dynamic library + /// Accesses the value at the symbol of the dynamic library. pub unsafe fn symbol(&self, symbol: &str) -> Result<*mut T, String> { // This function should have a lifetime constraint of 'a on // T but that feature is still unimplemented diff --git a/src/libstd/env.rs b/src/libstd/env.rs index 931cf46a58f..bcc109a71cb 100644 --- a/src/libstd/env.rs +++ b/src/libstd/env.rs @@ -261,7 +261,7 @@ pub fn set_var(k: &K, v: &V) os_imp::setenv(k.as_ref(), v.as_ref()) } -/// Remove an environment variable from the environment of the currently running process. +/// Removes an environment variable from the environment of the currently running process. /// /// # Examples /// diff --git a/src/libstd/ffi/c_str.rs b/src/libstd/ffi/c_str.rs index de91e5f3268..1910530c63a 100644 --- a/src/libstd/ffi/c_str.rs +++ b/src/libstd/ffi/c_str.rs @@ -133,7 +133,7 @@ pub struct CStr { pub struct NulError(usize, Vec); impl CString { - /// Create a new C-compatible string from a container of bytes. + /// Creates a new C-compatible string from a container of bytes. /// /// This method will consume the provided data and use the underlying bytes /// to construct a new string, ensuring that there is a trailing 0 byte. @@ -169,7 +169,7 @@ impl CString { } } - /// Create a C-compatible string from a byte vector without checking for + /// Creates a C-compatible string from a byte vector without checking for /// interior 0 bytes. /// /// This method is equivalent to `from_vec` except that no runtime assertion @@ -258,7 +258,7 @@ impl From for old_io::IoError { } impl CStr { - /// Cast a raw C string to a safe C string wrapper. + /// Casts a raw C string to a safe C string wrapper. /// /// This function will cast the provided `ptr` to the `CStr` wrapper which /// allows inspection and interoperation of non-owned C strings. This method @@ -301,7 +301,7 @@ impl CStr { mem::transmute(slice::from_raw_parts(ptr, len as usize + 1)) } - /// Return the inner pointer to this C string. + /// Returns the inner pointer to this C string. /// /// The returned pointer will be valid for as long as `self` is and points /// to a contiguous region of memory terminated with a 0 byte to represent @@ -311,7 +311,7 @@ impl CStr { self.inner.as_ptr() } - /// Convert this C string to a byte slice. + /// Converts this C string to a byte slice. /// /// This function will calculate the length of this string (which normally /// requires a linear amount of work to be done) and then return the @@ -329,7 +329,7 @@ impl CStr { &bytes[..bytes.len() - 1] } - /// Convert this C string to a byte slice containing the trailing 0 byte. + /// Converts this C string to a byte slice containing the trailing 0 byte. /// /// This function is the equivalent of `to_bytes` except that it will retain /// the trailing nul instead of chopping it off. diff --git a/src/libstd/ffi/mod.rs b/src/libstd/ffi/mod.rs index 1b7e913d46c..99becb67a5a 100644 --- a/src/libstd/ffi/mod.rs +++ b/src/libstd/ffi/mod.rs @@ -25,6 +25,6 @@ mod os_str; /// Freely convertible to an `&OsStr` slice. #[unstable(feature = "std_misc")] pub trait AsOsStr { - /// Convert to an `&OsStr` slice. + /// Converts to an `&OsStr` slice. fn as_os_str(&self) -> &OsStr; } diff --git a/src/libstd/ffi/os_str.rs b/src/libstd/ffi/os_str.rs index ab20efe25eb..5e61b29f34c 100644 --- a/src/libstd/ffi/os_str.rs +++ b/src/libstd/ffi/os_str.rs @@ -69,7 +69,7 @@ impl OsString { OsString { inner: Buf::from_string(String::new()) } } - /// Construct an `OsString` from a byte sequence. + /// Constructs an `OsString` from a byte sequence. /// /// # Platform behavior /// @@ -94,13 +94,13 @@ impl OsString { from_bytes_inner(bytes.into()) } - /// Convert to an `OsStr` slice. + /// Converts to an `OsStr` slice. #[stable(feature = "rust1", since = "1.0.0")] pub fn as_os_str(&self) -> &OsStr { self } - /// Convert the `OsString` into a `String` if it contains valid Unicode data. + /// Converts the `OsString` into a `String` if it contains valid Unicode data. /// /// On failure, ownership of the original `OsString` is returned. #[stable(feature = "rust1", since = "1.0.0")] @@ -108,7 +108,7 @@ impl OsString { self.inner.into_string().map_err(|buf| OsString { inner: buf} ) } - /// Extend the string with the given `&OsStr` slice. + /// Extends the string with the given `&OsStr` slice. #[stable(feature = "rust1", since = "1.0.0")] pub fn push>(&mut self, s: T) { self.inner.push_slice(&s.as_ref().inner) @@ -221,13 +221,13 @@ impl Hash for OsString { } impl OsStr { - /// Coerce into an `OsStr` slice. + /// Coerces into an `OsStr` slice. #[stable(feature = "rust1", since = "1.0.0")] pub fn new + ?Sized>(s: &S) -> &OsStr { s.as_ref() } - /// Coerce directly from a `&str` slice to a `&OsStr` slice. + /// Coerces directly from a `&str` slice to a `&OsStr` slice. #[stable(feature = "rust1", since = "1.0.0")] #[deprecated(since = "1.0.0", reason = "use `OsStr::new` instead")] @@ -235,7 +235,7 @@ impl OsStr { unsafe { mem::transmute(Slice::from_str(s)) } } - /// Yield a `&str` slice if the `OsStr` is valid unicode. + /// Yields a `&str` slice if the `OsStr` is valid unicode. /// /// This conversion may entail doing a check for UTF-8 validity. #[stable(feature = "rust1", since = "1.0.0")] @@ -243,7 +243,7 @@ impl OsStr { self.inner.to_str() } - /// Convert an `OsStr` to a `Cow`. + /// Converts an `OsStr` to a `Cow`. /// /// Any non-Unicode sequences are replaced with U+FFFD REPLACEMENT CHARACTER. #[stable(feature = "rust1", since = "1.0.0")] @@ -251,13 +251,13 @@ impl OsStr { self.inner.to_string_lossy() } - /// Copy the slice into an owned `OsString`. + /// Copies the slice into an owned `OsString`. #[stable(feature = "rust1", since = "1.0.0")] pub fn to_os_string(&self) -> OsString { OsString { inner: self.inner.to_owned() } } - /// Yield this `OsStr` as a byte slice. + /// Yields this `OsStr` as a byte slice. /// /// # Platform behavior /// @@ -275,7 +275,7 @@ impl OsStr { } } - /// Create a `CString` containing this `OsStr` data. + /// Creates a `CString` containing this `OsStr` data. /// /// Fails if the `OsStr` contains interior nulls. /// @@ -287,7 +287,7 @@ impl OsStr { self.to_bytes().and_then(|b| CString::new(b).ok()) } - /// Get the underlying byte representation. + /// Gets the underlying byte representation. /// /// Note: it is *crucial* that this API is private, to avoid /// revealing the internal, platform-specific encodings. diff --git a/src/libstd/fs.rs b/src/libstd/fs.rs index 914830d9dcf..cfa711db84d 100644 --- a/src/libstd/fs.rs +++ b/src/libstd/fs.rs @@ -171,7 +171,7 @@ impl File { OpenOptions::new().read(true).open(path) } - /// Open a file in write-only mode. + /// Opens a file in write-only mode. /// /// This function will create a file if it does not exist, /// and will truncate it if it does. @@ -201,7 +201,7 @@ impl File { self.path.as_ref().map(|p| &**p) } - /// Attempt to sync all OS-internal metadata to disk. + /// Attempts to sync all OS-internal metadata to disk. /// /// This function will attempt to ensure that all in-core data reaches the /// filesystem before returning. @@ -362,7 +362,7 @@ impl OpenOptions { OpenOptions(fs_imp::OpenOptions::new()) } - /// Set the option for read access. + /// Sets the option for read access. /// /// This option, when true, will indicate that the file should be /// `read`-able if opened. @@ -379,7 +379,7 @@ impl OpenOptions { self.0.read(read); self } - /// Set the option for write access. + /// Sets the option for write access. /// /// This option, when true, will indicate that the file should be /// `write`-able if opened. @@ -396,7 +396,7 @@ impl OpenOptions { self.0.write(write); self } - /// Set the option for the append mode. + /// Sets the option for the append mode. /// /// This option, when true, means that writes will append to a file instead /// of overwriting previous contents. @@ -413,7 +413,7 @@ impl OpenOptions { self.0.append(append); self } - /// Set the option for truncating a previous file. + /// Sets the option for truncating a previous file. /// /// If a file is successfully opened with this option set it will truncate /// the file to 0 length if it already exists. @@ -430,7 +430,7 @@ impl OpenOptions { self.0.truncate(truncate); self } - /// Set the option for creating a new file. + /// Sets the option for creating a new file. /// /// This option indicates whether a new file will be created if the file /// does not yet already exist. @@ -447,7 +447,7 @@ impl OpenOptions { self.0.create(create); self } - /// Open a file at `path` with the options specified by `self`. + /// Opens a file at `path` with the options specified by `self`. /// /// # Errors /// @@ -587,7 +587,7 @@ impl Permissions { #[stable(feature = "rust1", since = "1.0.0")] pub fn readonly(&self) -> bool { self.0.readonly() } - /// Modify the readonly flag for this set of permissions. + /// Modifies the readonly flag for this set of permissions. /// /// This operation does **not** modify the filesystem. To modify the /// filesystem use the `fs::set_permissions` function. @@ -670,7 +670,7 @@ impl DirEntry { pub fn path(&self) -> PathBuf { self.0.path() } } -/// Remove a file from the underlying filesystem. +/// Removes a file from the underlying filesystem. /// /// Note that, just because an unlink call was successful, it is not /// guaranteed that a file is immediately deleted (e.g. depending on @@ -856,7 +856,7 @@ pub fn read_link>(path: P) -> io::Result { fs_imp::readlink(path.as_ref()) } -/// Create a new, empty directory at the provided path +/// Creates a new, empty directory at the provided path /// /// # Errors /// @@ -906,7 +906,7 @@ pub fn create_dir_all>(path: P) -> io::Result<()> { create_dir(path) } -/// Remove an existing, empty directory +/// Removes an existing, empty directory. /// /// # Errors /// @@ -1058,7 +1058,7 @@ impl Iterator for WalkDir { reason = "the precise set of methods exposed on this trait may \ change and some methods may be removed")] pub trait PathExt { - /// Get information on the file, directory, etc at this path. + /// Gets information on the file, directory, etc at this path. /// /// Consult the `fs::stat` documentation for more info. /// diff --git a/src/libstd/io/cursor.rs b/src/libstd/io/cursor.rs index 6433c29bb9d..72743106abf 100644 --- a/src/libstd/io/cursor.rs +++ b/src/libstd/io/cursor.rs @@ -34,21 +34,21 @@ pub struct Cursor { } impl Cursor { - /// Create a new cursor wrapping the provided underlying I/O object. + /// Creates a new cursor wrapping the provided underlying I/O object. #[stable(feature = "rust1", since = "1.0.0")] pub fn new(inner: T) -> Cursor { Cursor { pos: 0, inner: inner } } - /// Consume this cursor, returning the underlying value. + /// Consumes this cursor, returning the underlying value. #[stable(feature = "rust1", since = "1.0.0")] pub fn into_inner(self) -> T { self.inner } - /// Get a reference to the underlying value in this cursor. + /// Gets a reference to the underlying value in this cursor. #[stable(feature = "rust1", since = "1.0.0")] pub fn get_ref(&self) -> &T { &self.inner } - /// Get a mutable reference to the underlying value in this cursor. + /// Gets a mutable reference to the underlying value in this cursor. /// /// Care should be taken to avoid modifying the internal I/O state of the /// underlying value as it may corrupt this cursor's position. diff --git a/src/libstd/io/error.rs b/src/libstd/io/error.rs index 7428d0a8e35..a49039b1ec4 100644 --- a/src/libstd/io/error.rs +++ b/src/libstd/io/error.rs @@ -191,7 +191,7 @@ impl Error { } } - /// Return the corresponding `ErrorKind` for this error. + /// Returns the corresponding `ErrorKind` for this error. #[stable(feature = "rust1", since = "1.0.0")] pub fn kind(&self) -> ErrorKind { match self.repr { diff --git a/src/libstd/io/mod.rs b/src/libstd/io/mod.rs index f0f37117ed3..ef836a19461 100644 --- a/src/libstd/io/mod.rs +++ b/src/libstd/io/mod.rs @@ -220,14 +220,14 @@ pub trait Read { append_to_string(buf, |b| read_to_end(self, b)) } - /// Create a "by reference" adaptor for this instance of `Read`. + /// Creates a "by reference" adaptor for this instance of `Read`. /// /// The returned adaptor also implements `Read` and will simply borrow this /// current reader. #[stable(feature = "rust1", since = "1.0.0")] fn by_ref(&mut self) -> &mut Self where Self: Sized { self } - /// Transform this `Read` instance to an `Iterator` over its bytes. + /// Transforms this `Read` instance to an `Iterator` over its bytes. /// /// The returned type implements `Iterator` where the `Item` is `Result`. The yielded item is `Ok` if a byte was successfully read and @@ -238,7 +238,7 @@ pub trait Read { Bytes { inner: self } } - /// Transform this `Read` instance to an `Iterator` over `char`s. + /// Transforms this `Read` instance to an `Iterator` over `char`s. /// /// This adaptor will attempt to interpret this reader as an UTF-8 encoded /// sequence of characters. The returned iterator will return `None` once @@ -255,7 +255,7 @@ pub trait Read { Chars { inner: self } } - /// Create an adaptor which will chain this stream with another. + /// Creates an adaptor which will chain this stream with another. /// /// The returned `Read` instance will first read all bytes from this object /// until EOF is encountered. Afterwards the output is equivalent to the @@ -265,7 +265,7 @@ pub trait Read { Chain { first: self, second: next, done_first: false } } - /// Create an adaptor which will read at most `limit` bytes from it. + /// Creates an adaptor which will read at most `limit` bytes from it. /// /// This function returns a new instance of `Read` which will read at most /// `limit` bytes, after which it will always return EOF (`Ok(0)`). Any @@ -406,7 +406,7 @@ pub trait Write { } } - /// Create a "by reference" adaptor for this instance of `Write`. + /// Creates a "by reference" adaptor for this instance of `Write`. /// /// The returned adaptor also implements `Write` and will simply borrow this /// current writer. diff --git a/src/libstd/io/stdio.rs b/src/libstd/io/stdio.rs index 2850d92e34d..cd6af77daa9 100644 --- a/src/libstd/io/stdio.rs +++ b/src/libstd/io/stdio.rs @@ -45,7 +45,7 @@ struct StdoutRaw(stdio::Stdout); /// the `std::io::stdio::stderr_raw` function. struct StderrRaw(stdio::Stderr); -/// Construct a new raw handle to the standard input of this process. +/// Constructs a new raw handle to the standard input of this process. /// /// The returned handle does not interact with any other handles created nor /// handles returned by `std::io::stdin`. Data buffered by the `std::io::stdin` @@ -54,7 +54,7 @@ struct StderrRaw(stdio::Stderr); /// The returned handle has no external synchronization or buffering. fn stdin_raw() -> StdinRaw { StdinRaw(stdio::Stdin::new()) } -/// Construct a new raw handle to the standard input stream of this process. +/// Constructs a new raw handle to the standard input stream of this process. /// /// The returned handle does not interact with any other handles created nor /// handles returned by `std::io::stdout`. Note that data is buffered by the @@ -65,7 +65,7 @@ fn stdin_raw() -> StdinRaw { StdinRaw(stdio::Stdin::new()) } /// top. fn stdout_raw() -> StdoutRaw { StdoutRaw(stdio::Stdout::new()) } -/// Construct a new raw handle to the standard input stream of this process. +/// Constructs a new raw handle to the standard input stream of this process. /// /// The returned handle does not interact with any other handles created nor /// handles returned by `std::io::stdout`. @@ -109,7 +109,7 @@ pub struct StdinLock<'a> { inner: MutexGuard<'a, BufReader>, } -/// Create a new handle to the global standard input stream of this process. +/// Creates a new handle to the global standard input stream of this process. /// /// The handle returned refers to a globally shared buffer between all threads. /// Access is synchronized and can be explicitly controlled with the `lock()` @@ -139,7 +139,7 @@ pub fn stdin() -> Stdin { } impl Stdin { - /// Lock this handle to the standard input stream, returning a readable + /// Locks this handle to the standard input stream, returning a readable /// guard. /// /// The lock is released when the returned lock goes out of scope. The @@ -243,7 +243,7 @@ pub fn stdout() -> Stdout { } impl Stdout { - /// Lock this handle to the standard output stream, returning a writable + /// Locks this handle to the standard output stream, returning a writable /// guard. /// /// The lock is released when the returned lock goes out of scope. The @@ -315,7 +315,7 @@ pub fn stderr() -> Stderr { } impl Stderr { - /// Lock this handle to the standard error stream, returning a writable + /// Locks this handle to the standard error stream, returning a writable /// guard. /// /// The lock is released when the returned lock goes out of scope. The diff --git a/src/libstd/net/ip.rs b/src/libstd/net/ip.rs index c8b19287477..8d4af4689af 100644 --- a/src/libstd/net/ip.rs +++ b/src/libstd/net/ip.rs @@ -58,7 +58,7 @@ pub enum Ipv6MulticastScope { } impl Ipv4Addr { - /// Create a new IPv4 address from four eight-bit octets. + /// Creates a new IPv4 address from four eight-bit octets. /// /// The result will represent the IP address a.b.c.d #[stable(feature = "rust1", since = "1.0.0")] @@ -127,7 +127,7 @@ impl Ipv4Addr { self.octets()[0] >= 224 && self.octets()[0] <= 239 } - /// Convert this address to an IPv4-compatible IPv6 address + /// Converts this address to an IPv4-compatible IPv6 address /// /// a.b.c.d becomes ::a.b.c.d #[stable(feature = "rust1", since = "1.0.0")] @@ -137,7 +137,7 @@ impl Ipv4Addr { ((self.octets()[2] as u16) << 8) | self.octets()[3] as u16) } - /// Convert this address to an IPv4-mapped IPv6 address + /// Converts this address to an IPv4-mapped IPv6 address /// /// a.b.c.d becomes ::ffff:a.b.c.d #[stable(feature = "rust1", since = "1.0.0")] @@ -220,7 +220,7 @@ impl FromInner for Ipv4Addr { } impl Ipv6Addr { - /// Create a new IPv6 address from eight 16-bit segments. + /// Creates a new IPv6 address from eight 16-bit segments. /// /// The result will represent the IP address a:b:c:d:e:f:g:h #[stable(feature = "rust1", since = "1.0.0")] @@ -234,7 +234,7 @@ impl Ipv6Addr { } } - /// Return the eight 16-bit segments that make up this address + /// Returns the eight 16-bit segments that make up this address #[stable(feature = "rust1", since = "1.0.0")] pub fn segments(&self) -> [u16; 8] { [ntoh(self.inner.s6_addr[0]), @@ -324,7 +324,7 @@ impl Ipv6Addr { (self.segments()[0] & 0xff00) == 0xff00 } - /// Convert this address to an IPv4 address. Returns None if this address is + /// Converts this address to an IPv4 address. Returns None if this address is /// neither IPv4-compatible or IPv4-mapped. /// /// ::a.b.c.d and ::ffff:a.b.c.d become a.b.c.d diff --git a/src/libstd/net/tcp.rs b/src/libstd/net/tcp.rs index 2da6f7420ac..209a0032fb4 100644 --- a/src/libstd/net/tcp.rs +++ b/src/libstd/net/tcp.rs @@ -82,7 +82,7 @@ pub struct TcpListener(net_imp::TcpListener); pub struct Incoming<'a> { listener: &'a TcpListener } impl TcpStream { - /// Open a TCP connection to a remote host. + /// Opens a TCP connection to a remote host. /// /// `addr` is an address of the remote host. Anything which implements /// `ToSocketAddrs` trait can be supplied for the address; see this trait @@ -104,7 +104,7 @@ impl TcpStream { self.0.socket_addr() } - /// Shut down the read, write, or both halves of this connection. + /// Shuts down the read, write, or both halves of this connection. /// /// This function will cause all pending and future I/O on the specified /// portions to return immediately with an appropriate value (see the @@ -114,7 +114,7 @@ impl TcpStream { self.0.shutdown(how) } - /// Create a new independently owned handle to the underlying socket. + /// Creates a new independently owned handle to the underlying socket. /// /// The returned `TcpStream` is a reference to the same stream that this /// object references. Both handles will read and write the same stream of @@ -190,7 +190,7 @@ impl TcpListener { self.0.socket_addr() } - /// Create a new independently owned handle to the underlying socket. + /// Creates a new independently owned handle to the underlying socket. /// /// The returned `TcpListener` is a reference to the same socket that this /// object references. Both handles can be used to accept incoming diff --git a/src/libstd/net/udp.rs b/src/libstd/net/udp.rs index bec9c09bc31..1955b895300 100644 --- a/src/libstd/net/udp.rs +++ b/src/libstd/net/udp.rs @@ -85,7 +85,7 @@ impl UdpSocket { self.0.socket_addr() } - /// Create a new independently owned handle to the underlying socket. + /// Creates a new independently owned handle to the underlying socket. /// /// The returned `UdpSocket` is a reference to the same socket that this /// object references. Both handles will read and write the same port, and @@ -100,7 +100,7 @@ impl UdpSocket { self.0.set_broadcast(on) } - /// Set the multicast loop flag to the specified value + /// Sets the multicast loop flag to the specified value /// /// This lets multicast packets loop back to local sockets (if enabled) pub fn set_multicast_loop(&self, on: bool) -> io::Result<()> { diff --git a/src/libstd/num/f32.rs b/src/libstd/num/f32.rs index 6128469c60e..736f6d2f4f4 100644 --- a/src/libstd/num/f32.rs +++ b/src/libstd/num/f32.rs @@ -527,7 +527,7 @@ impl f32 { #[inline] pub fn round(self) -> f32 { num::Float::round(self) } - /// Return the integer part of a number. + /// Returns the integer part of a number. /// /// ``` /// let f = 3.3_f32; @@ -666,7 +666,7 @@ impl f32 { #[inline] pub fn mul_add(self, a: f32, b: f32) -> f32 { num::Float::mul_add(self, a, b) } - /// Take the reciprocal (inverse) of a number, `1/x`. + /// Takes the reciprocal (inverse) of a number, `1/x`. /// /// ``` /// use std::f32; @@ -680,7 +680,7 @@ impl f32 { #[inline] pub fn recip(self) -> f32 { num::Float::recip(self) } - /// Raise a number to an integer power. + /// Raises a number to an integer power. /// /// Using this function is generally faster than using `powf` /// @@ -696,7 +696,7 @@ impl f32 { #[inline] pub fn powi(self, n: i32) -> f32 { num::Float::powi(self, n) } - /// Raise a number to a floating point power. + /// Raises a number to a floating point power. /// /// ``` /// use std::f32; @@ -710,7 +710,7 @@ impl f32 { #[inline] pub fn powf(self, n: f32) -> f32 { num::Float::powf(self, n) } - /// Take the square root of a number. + /// Takes the square root of a number. /// /// Returns NaN if `self` is a negative number. /// @@ -729,7 +729,7 @@ impl f32 { #[inline] pub fn sqrt(self) -> f32 { num::Float::sqrt(self) } - /// Take the reciprocal (inverse) square root of a number, `1/sqrt(x)`. + /// Takes the reciprocal (inverse) square root of a number, `1/sqrt(x)`. /// /// ``` /// # #![feature(std_misc)] @@ -852,7 +852,7 @@ impl f32 { #[inline] pub fn log10(self) -> f32 { num::Float::log10(self) } - /// Convert radians to degrees. + /// Converts radians to degrees. /// /// ``` /// # #![feature(std_misc)] @@ -868,7 +868,7 @@ impl f32 { #[inline] pub fn to_degrees(self) -> f32 { num::Float::to_degrees(self) } - /// Convert degrees to radians. + /// Converts degrees to radians. /// /// ``` /// # #![feature(std_misc)] @@ -1003,7 +1003,7 @@ impl f32 { unsafe { cmath::fdimf(self, other) } } - /// Take the cubic root of a number. + /// Takes the cubic root of a number. /// /// ``` /// use std::f32; @@ -1021,7 +1021,7 @@ impl f32 { unsafe { cmath::cbrtf(self) } } - /// Calculate the length of the hypotenuse of a right-angle triangle given + /// Calculates the length of the hypotenuse of a right-angle triangle given /// legs of length `x` and `y`. /// /// ``` diff --git a/src/libstd/num/f64.rs b/src/libstd/num/f64.rs index 794853f6f70..bb9067eca13 100644 --- a/src/libstd/num/f64.rs +++ b/src/libstd/num/f64.rs @@ -534,7 +534,7 @@ impl f64 { #[inline] pub fn round(self) -> f64 { num::Float::round(self) } - /// Return the integer part of a number. + /// Returns the integer part of a number. /// /// ``` /// let f = 3.3_f64; @@ -671,7 +671,7 @@ impl f64 { #[inline] pub fn mul_add(self, a: f64, b: f64) -> f64 { num::Float::mul_add(self, a, b) } - /// Take the reciprocal (inverse) of a number, `1/x`. + /// Takes the reciprocal (inverse) of a number, `1/x`. /// /// ``` /// let x = 2.0_f64; @@ -683,7 +683,7 @@ impl f64 { #[inline] pub fn recip(self) -> f64 { num::Float::recip(self) } - /// Raise a number to an integer power. + /// Raises a number to an integer power. /// /// Using this function is generally faster than using `powf` /// @@ -697,7 +697,7 @@ impl f64 { #[inline] pub fn powi(self, n: i32) -> f64 { num::Float::powi(self, n) } - /// Raise a number to a floating point power. + /// Raises a number to a floating point power. /// /// ``` /// let x = 2.0_f64; @@ -709,7 +709,7 @@ impl f64 { #[inline] pub fn powf(self, n: f64) -> f64 { num::Float::powf(self, n) } - /// Take the square root of a number. + /// Takes the square root of a number. /// /// Returns NaN if `self` is a negative number. /// @@ -726,7 +726,7 @@ impl f64 { #[inline] pub fn sqrt(self) -> f64 { num::Float::sqrt(self) } - /// Take the reciprocal (inverse) square root of a number, `1/sqrt(x)`. + /// Takes the reciprocal (inverse) square root of a number, `1/sqrt(x)`. /// /// ``` /// # #![feature(std_misc)] @@ -835,7 +835,7 @@ impl f64 { #[inline] pub fn log10(self) -> f64 { num::Float::log10(self) } - /// Convert radians to degrees. + /// Converts radians to degrees. /// /// ``` /// use std::f64::consts; @@ -850,7 +850,7 @@ impl f64 { #[inline] pub fn to_degrees(self) -> f64 { num::Float::to_degrees(self) } - /// Convert degrees to radians. + /// Converts degrees to radians. /// /// ``` /// use std::f64::consts; @@ -978,7 +978,7 @@ impl f64 { unsafe { cmath::fdim(self, other) } } - /// Take the cubic root of a number. + /// Takes the cubic root of a number. /// /// ``` /// let x = 8.0_f64; @@ -994,7 +994,7 @@ impl f64 { unsafe { cmath::cbrt(self) } } - /// Calculate the length of the hypotenuse of a right-angle triangle given + /// Calculates the length of the hypotenuse of a right-angle triangle given /// legs of length `x` and `y`. /// /// ``` diff --git a/src/libstd/num/mod.rs b/src/libstd/num/mod.rs index ea516e5b20b..e0b9c720dbb 100644 --- a/src/libstd/num/mod.rs +++ b/src/libstd/num/mod.rs @@ -383,7 +383,7 @@ pub trait Float /// ``` #[stable(feature = "rust1", since = "1.0.0")] fn round(self) -> Self; - /// Return the integer part of a number. + /// Returns the integer part of a number. /// /// ``` /// use std::num::Float; @@ -509,7 +509,7 @@ pub trait Float #[unstable(feature = "std_misc", reason = "unsure about its place in the world")] fn mul_add(self, a: Self, b: Self) -> Self; - /// Take the reciprocal (inverse) of a number, `1/x`. + /// Takes the reciprocal (inverse) of a number, `1/x`. /// /// ``` /// # #![feature(std_misc)] @@ -524,7 +524,7 @@ pub trait Float reason = "unsure about its place in the world")] fn recip(self) -> Self; - /// Raise a number to an integer power. + /// Raises a number to an integer power. /// /// Using this function is generally faster than using `powf` /// @@ -538,7 +538,7 @@ pub trait Float /// ``` #[stable(feature = "rust1", since = "1.0.0")] fn powi(self, n: i32) -> Self; - /// Raise a number to a floating point power. + /// Raises a number to a floating point power. /// /// ``` /// use std::num::Float; @@ -550,7 +550,7 @@ pub trait Float /// ``` #[stable(feature = "rust1", since = "1.0.0")] fn powf(self, n: Self) -> Self; - /// Take the square root of a number. + /// Takes the square root of a number. /// /// Returns NaN if `self` is a negative number. /// @@ -569,7 +569,7 @@ pub trait Float #[stable(feature = "rust1", since = "1.0.0")] fn sqrt(self) -> Self; - /// Take the reciprocal (inverse) square root of a number, `1/sqrt(x)`. + /// Takes the reciprocal (inverse) square root of a number, `1/sqrt(x)`. /// /// ``` /// # #![feature(std_misc)] @@ -679,7 +679,7 @@ pub trait Float #[stable(feature = "rust1", since = "1.0.0")] fn log10(self) -> Self; - /// Convert radians to degrees. + /// Converts radians to degrees. /// /// ``` /// use std::num::Float; @@ -693,7 +693,7 @@ pub trait Float /// ``` #[unstable(feature = "std_misc", reason = "desirability is unclear")] fn to_degrees(self) -> Self; - /// Convert degrees to radians. + /// Converts degrees to radians. /// /// ``` /// # #![feature(std_misc)] @@ -807,7 +807,7 @@ pub trait Float /// ``` #[unstable(feature = "std_misc", reason = "may be renamed")] fn abs_sub(self, other: Self) -> Self; - /// Take the cubic root of a number. + /// Takes the cubic root of a number. /// /// ``` /// # #![feature(std_misc)] @@ -822,7 +822,7 @@ pub trait Float /// ``` #[unstable(feature = "std_misc", reason = "may be renamed")] fn cbrt(self) -> Self; - /// Calculate the length of the hypotenuse of a right-angle triangle given + /// Calculates the length of the hypotenuse of a right-angle triangle given /// legs of length `x` and `y`. /// /// ``` diff --git a/src/libstd/path.rs b/src/libstd/path.rs index 4471b5afa84..cdc5cecbf38 100644 --- a/src/libstd/path.rs +++ b/src/libstd/path.rs @@ -312,7 +312,7 @@ impl<'a> Prefix<'a> { } - /// Determine if the prefix is verbatim, i.e. begins `\\?\`. + /// Determines if the prefix is verbatim, i.e. begins `\\?\`. #[inline] #[stable(feature = "rust1", since = "1.0.0")] pub fn is_verbatim(&self) -> bool { @@ -341,7 +341,7 @@ impl<'a> Prefix<'a> { // Exposed parsing helpers //////////////////////////////////////////////////////////////////////////////// -/// Determine whether the character is one of the permitted path +/// Determines whether the character is one of the permitted path /// separators for the current platform. /// /// # Examples @@ -524,7 +524,7 @@ pub enum Component<'a> { } impl<'a> Component<'a> { - /// Extract the underlying `OsStr` slice + /// Extracts the underlying `OsStr` slice #[stable(feature = "rust1", since = "1.0.0")] pub fn as_os_str(self) -> &'a OsStr { match self { @@ -629,7 +629,7 @@ impl<'a> Components<'a> { } } - /// Extract a slice corresponding to the portion of the path remaining for iteration. + /// Extracts a slice corresponding to the portion of the path remaining for iteration. /// /// # Examples /// @@ -750,7 +750,7 @@ impl<'a> AsRef for Components<'a> { } impl<'a> Iter<'a> { - /// Extract a slice corresponding to the portion of the path remaining for iteration. + /// Extracts a slice corresponding to the portion of the path remaining for iteration. #[stable(feature = "rust1", since = "1.0.0")] pub fn as_path(&self) -> &'a Path { self.inner.as_path() @@ -941,19 +941,19 @@ impl PathBuf { unsafe { mem::transmute(self) } } - /// Allocate an empty `PathBuf`. + /// Allocates an empty `PathBuf`. #[stable(feature = "rust1", since = "1.0.0")] pub fn new() -> PathBuf { PathBuf { inner: OsString::new() } } - /// Coerce to a `Path` slice. + /// Coerces to a `Path` slice. #[stable(feature = "rust1", since = "1.0.0")] pub fn as_path(&self) -> &Path { self } - /// Extend `self` with `path`. + /// Extends `self` with `path`. /// /// If `path` is absolute, it replaces the current path. /// @@ -1064,7 +1064,7 @@ impl PathBuf { true } - /// Consume the `PathBuf`, yielding its internal `OsString` storage + /// Consumes the `PathBuf`, yielding its internal `OsString` storage. #[stable(feature = "rust1", since = "1.0.0")] pub fn into_os_string(self) -> OsString { self.inner @@ -1254,7 +1254,7 @@ impl Path { unsafe { mem::transmute(s.as_ref()) } } - /// Yield the underlying `OsStr` slice. + /// Yields the underlying `OsStr` slice. /// /// # Examples /// @@ -1268,7 +1268,7 @@ impl Path { &self.inner } - /// Yield a `&str` slice if the `Path` is valid unicode. + /// Yields a `&str` slice if the `Path` is valid unicode. /// /// This conversion may entail doing a check for UTF-8 validity. /// @@ -1284,7 +1284,7 @@ impl Path { self.inner.to_str() } - /// Convert a `Path` to a `Cow`. + /// Converts a `Path` to a `Cow`. /// /// Any non-Unicode sequences are replaced with U+FFFD REPLACEMENT CHARACTER. /// @@ -1300,7 +1300,7 @@ impl Path { self.inner.to_string_lossy() } - /// Convert a `Path` to an owned `PathBuf`. + /// Converts a `Path` to an owned `PathBuf`. /// /// # Examples /// @@ -1477,7 +1477,7 @@ impl Path { iter_after(self.components().rev(), child.as_ref().components().rev()).is_some() } - /// Extract the stem (non-extension) portion of `self.file()`. + /// Extracts the stem (non-extension) portion of `self.file()`. /// /// The stem is: /// @@ -1500,7 +1500,7 @@ impl Path { self.file_name().map(split_file_at_dot).and_then(|(before, after)| before.or(after)) } - /// Extract the extension of `self.file()`, if possible. + /// Extracts the extension of `self.file()`, if possible. /// /// The extension is: /// @@ -1714,7 +1714,7 @@ impl cmp::Ord for Path { #[unstable(feature = "std_misc")] #[deprecated(since = "1.0.0", reason = "use std::convert::AsRef instead")] pub trait AsPath { - /// Convert to a `Path`. + /// Converts to a `Path`. #[unstable(feature = "std_misc")] fn as_path(&self) -> &Path; } diff --git a/src/libstd/process.rs b/src/libstd/process.rs index cac1540d0ec..7306dd38260 100644 --- a/src/libstd/process.rs +++ b/src/libstd/process.rs @@ -194,7 +194,7 @@ impl Command { self } - /// Set the working directory for the child process. + /// Sets the working directory for the child process. #[stable(feature = "process", since = "1.0.0")] pub fn current_dir>(&mut self, dir: P) -> &mut Command { self.inner.cwd(dir.as_ref().as_ref()); @@ -396,7 +396,7 @@ impl ExitStatus { self.0.success() } - /// Return the exit code of the process, if any. + /// Returns the exit code of the process, if any. /// /// On Unix, this will return `None` if the process was terminated /// by a signal; `std::os::unix` provides an extension trait for @@ -453,7 +453,7 @@ impl Child { unsafe { self.handle.kill() } } - /// Wait for the child to exit completely, returning the status that it + /// Waits for the child to exit completely, returning the status that it /// exited with. This function will continue to have the same return value /// after it has been called at least once. /// @@ -474,7 +474,7 @@ impl Child { } } - /// Simultaneously wait for the child to exit and collect all remaining + /// Simultaneously waits for the child to exit and collect all remaining /// output on the stdout/stderr handles, returning a `Output` /// instance. /// diff --git a/src/libstd/sync/barrier.rs b/src/libstd/sync/barrier.rs index ebf4d337749..34fcf6cdadd 100644 --- a/src/libstd/sync/barrier.rs +++ b/src/libstd/sync/barrier.rs @@ -49,7 +49,7 @@ struct BarrierState { pub struct BarrierWaitResult(bool); impl Barrier { - /// Create a new barrier that can block a given number of threads. + /// Creates a new barrier that can block a given number of threads. /// /// A barrier will block `n`-1 threads which call `wait` and then wake up /// all threads at once when the `n`th thread calls `wait`. @@ -65,7 +65,7 @@ impl Barrier { } } - /// Block the current thread until all threads has rendezvoused here. + /// Blocks the current thread until all threads has rendezvoused here. /// /// Barriers are re-usable after all threads have rendezvoused once, and can /// be used continuously. @@ -97,7 +97,7 @@ impl Barrier { } impl BarrierWaitResult { - /// Return whether this thread from `wait` is the "leader thread". + /// Returns whether this thread from `wait` is the "leader thread". /// /// Only one thread will have `true` returned from their result, all other /// threads will have `false` returned. diff --git a/src/libstd/sync/condvar.rs b/src/libstd/sync/condvar.rs index 654b33f1a57..fcb0d2c0b2d 100644 --- a/src/libstd/sync/condvar.rs +++ b/src/libstd/sync/condvar.rs @@ -102,7 +102,7 @@ impl Condvar { } } - /// Block the current thread until this condition variable receives a + /// Blocks the current thread until this condition variable receives a /// notification. /// /// This function will atomically unlock the mutex specified (represented by @@ -137,7 +137,7 @@ impl Condvar { } } - /// Wait on this condition variable for a notification, timing out after a + /// Waits on this condition variable for a notification, timing out after a /// specified duration. /// /// The semantics of this function are equivalent to `wait()` @@ -169,7 +169,7 @@ impl Condvar { self.wait_timeout_ms(guard, dur.num_milliseconds() as u32) } - /// Wait on this condition variable for a notification, timing out after a + /// Waits on this condition variable for a notification, timing out after a /// specified duration. /// /// The semantics of this function are equivalent to `wait_timeout` except @@ -189,7 +189,7 @@ impl Condvar { } } - /// Wake up one blocked thread on this condvar. + /// Wakes up one blocked thread on this condvar. /// /// If there is a blocked thread on this condition variable, then it will /// be woken up from its call to `wait` or `wait_timeout`. Calls to @@ -199,7 +199,7 @@ impl Condvar { #[stable(feature = "rust1", since = "1.0.0")] pub fn notify_one(&self) { unsafe { self.inner.inner.notify_one() } } - /// Wake up all blocked threads on this condvar. + /// Wakes up all blocked threads on this condvar. /// /// This method will ensure that any current waiters on the condition /// variable are awoken. Calls to `notify_all()` are not buffered in any @@ -218,7 +218,7 @@ impl Drop for Condvar { } impl StaticCondvar { - /// Block the current thread until this condition variable receives a + /// Blocks the current thread until this condition variable receives a /// notification. /// /// See `Condvar::wait`. @@ -239,7 +239,7 @@ impl StaticCondvar { } } - /// Wait on this condition variable for a notification, timing out after a + /// Waits on this condition variable for a notification, timing out after a /// specified duration. /// /// See `Condvar::wait_timeout`. @@ -260,7 +260,7 @@ impl StaticCondvar { } } - /// Wait on this condition variable for a notification, timing out after a + /// Waits on this condition variable for a notification, timing out after a /// specified duration. /// /// The implementation will repeatedly wait while the duration has not @@ -306,21 +306,21 @@ impl StaticCondvar { poison::map_result(guard_result, |g| (g, true)) } - /// Wake up one blocked thread on this condvar. + /// Wakes up one blocked thread on this condvar. /// /// See `Condvar::notify_one`. #[unstable(feature = "std_misc", reason = "may be merged with Condvar in the future")] pub fn notify_one(&'static self) { unsafe { self.inner.notify_one() } } - /// Wake up all blocked threads on this condvar. + /// Wakes up all blocked threads on this condvar. /// /// See `Condvar::notify_all`. #[unstable(feature = "std_misc", reason = "may be merged with Condvar in the future")] pub fn notify_all(&'static self) { unsafe { self.inner.notify_all() } } - /// Deallocate all resources associated with this static condvar. + /// Deallocates all resources associated with this static condvar. /// /// This method is unsafe to call as there is no guarantee that there are no /// active users of the condvar, and this also doesn't prevent any future diff --git a/src/libstd/sync/mpsc/mod.rs b/src/libstd/sync/mpsc/mod.rs index 93b27b6ce9e..422439fadc1 100644 --- a/src/libstd/sync/mpsc/mod.rs +++ b/src/libstd/sync/mpsc/mod.rs @@ -750,7 +750,7 @@ impl Receiver { } } - /// Attempt to wait for a value on this receiver, returning an error if the + /// Attempts to wait for a value on this receiver, returning an error if the /// corresponding channel has hung up. /// /// This function will always block the current thread if there is no data diff --git a/src/libstd/sync/mpsc/select.rs b/src/libstd/sync/mpsc/select.rs index b509b3472ee..b8ad92841f2 100644 --- a/src/libstd/sync/mpsc/select.rs +++ b/src/libstd/sync/mpsc/select.rs @@ -254,11 +254,11 @@ impl Select { } impl<'rx, T: Send> Handle<'rx, T> { - /// Retrieve the id of this handle. + /// Retrieves the id of this handle. #[inline] pub fn id(&self) -> usize { self.id } - /// Block to receive a value on the underlying receiver, returning `Some` on + /// Blocks to receive a value on the underlying receiver, returning `Some` on /// success or `None` if the channel disconnects. This function has the same /// semantics as `Receiver.recv` pub fn recv(&mut self) -> Result { self.rx.recv() } diff --git a/src/libstd/sync/mutex.rs b/src/libstd/sync/mutex.rs index 46fb20cd6a2..7896870ea07 100644 --- a/src/libstd/sync/mutex.rs +++ b/src/libstd/sync/mutex.rs @@ -232,7 +232,7 @@ impl Mutex { } } - /// Determine whether the lock is poisoned. + /// Determines whether the lock is poisoned. /// /// If another thread is active, the lock can still become poisoned at any /// time. You should not trust a `false` value for program correctness diff --git a/src/libstd/sync/once.rs b/src/libstd/sync/once.rs index 258cf1d38a8..948965f5efa 100644 --- a/src/libstd/sync/once.rs +++ b/src/libstd/sync/once.rs @@ -51,7 +51,7 @@ pub const ONCE_INIT: Once = Once { }; impl Once { - /// Perform an initialization routine once and only once. The given closure + /// Performs an initialization routine once and only once. The given closure /// will be executed if this is the first time `call_once` has been called, /// and otherwise the routine will *not* be invoked. /// diff --git a/src/libstd/sync/rwlock.rs b/src/libstd/sync/rwlock.rs index eb6d46a5dda..1ea92d5eff7 100644 --- a/src/libstd/sync/rwlock.rs +++ b/src/libstd/sync/rwlock.rs @@ -169,7 +169,7 @@ impl RwLock { RwLockReadGuard::new(&*self.inner, &self.data) } - /// Attempt to acquire this lock with shared read access. + /// Attempts to acquire this lock with shared read access. /// /// This function will never block and will return immediately if `read` /// would otherwise succeed. Returns `Some` of an RAII guard which will @@ -194,7 +194,7 @@ impl RwLock { } } - /// Lock this rwlock with exclusive write access, blocking the current + /// Locks this rwlock with exclusive write access, blocking the current /// thread until it can be acquired. /// /// This function will not return while other writers or other readers @@ -215,7 +215,7 @@ impl RwLock { RwLockWriteGuard::new(&*self.inner, &self.data) } - /// Attempt to lock this rwlock with exclusive write access. + /// Attempts to lock this rwlock with exclusive write access. /// /// This function does not ever block, and it will return `None` if a call /// to `write` would otherwise block. If successful, an RAII guard is @@ -237,7 +237,7 @@ impl RwLock { } } - /// Determine whether the lock is poisoned. + /// Determines whether the lock is poisoned. /// /// If another thread is active, the lock can still become poisoned at any /// time. You should not trust a `false` value for program correctness @@ -287,7 +287,7 @@ impl StaticRwLock { RwLockReadGuard::new(self, &DUMMY.0) } - /// Attempt to acquire this lock with shared read access. + /// Attempts to acquire this lock with shared read access. /// /// See `RwLock::try_read`. #[inline] @@ -302,7 +302,7 @@ impl StaticRwLock { } } - /// Lock this rwlock with exclusive write access, blocking the current + /// Locks this rwlock with exclusive write access, blocking the current /// thread until it can be acquired. /// /// See `RwLock::write`. @@ -314,7 +314,7 @@ impl StaticRwLock { RwLockWriteGuard::new(self, &DUMMY.0) } - /// Attempt to lock this rwlock with exclusive write access. + /// Attempts to lock this rwlock with exclusive write access. /// /// See `RwLock::try_write`. #[inline] @@ -329,7 +329,7 @@ impl StaticRwLock { } } - /// Deallocate all resources associated with this static lock. + /// Deallocates all resources associated with this static lock. /// /// This method is unsafe to call as there is no guarantee that there are no /// active users of the lock, and this also doesn't prevent any future users diff --git a/src/libstd/sys/common/condvar.rs b/src/libstd/sys/common/condvar.rs index 32fa6ec5903..9f46b0c3824 100644 --- a/src/libstd/sys/common/condvar.rs +++ b/src/libstd/sys/common/condvar.rs @@ -31,15 +31,15 @@ impl Condvar { #[inline] pub unsafe fn new() -> Condvar { Condvar(imp::Condvar::new()) } - /// Signal one waiter on this condition variable to wake up. + /// Signals one waiter on this condition variable to wake up. #[inline] pub unsafe fn notify_one(&self) { self.0.notify_one() } - /// Awaken all current waiters on this condition variable. + /// Awakens all current waiters on this condition variable. #[inline] pub unsafe fn notify_all(&self) { self.0.notify_all() } - /// Wait for a signal on the specified mutex. + /// Waits for a signal on the specified mutex. /// /// Behavior is undefined if the mutex is not locked by the current thread. /// Behavior is also undefined if more than one mutex is used concurrently @@ -47,7 +47,7 @@ impl Condvar { #[inline] pub unsafe fn wait(&self, mutex: &Mutex) { self.0.wait(mutex::raw(mutex)) } - /// Wait for a signal on the specified mutex with a timeout duration + /// Waits for a signal on the specified mutex with a timeout duration /// specified by `dur` (a relative time into the future). /// /// Behavior is undefined if the mutex is not locked by the current thread. @@ -58,7 +58,7 @@ impl Condvar { self.0.wait_timeout(mutex::raw(mutex), dur) } - /// Deallocate all resources associated with this condition variable. + /// Deallocates all resources associated with this condition variable. /// /// Behavior is undefined if there are current or will be future users of /// this condition variable. diff --git a/src/libstd/sys/common/mutex.rs b/src/libstd/sys/common/mutex.rs index 0ca22826700..1f9dd54192c 100644 --- a/src/libstd/sys/common/mutex.rs +++ b/src/libstd/sys/common/mutex.rs @@ -24,14 +24,14 @@ unsafe impl Sync for Mutex {} pub const MUTEX_INIT: Mutex = Mutex(imp::MUTEX_INIT); impl Mutex { - /// Lock the mutex blocking the current thread until it is available. + /// Locks the mutex blocking the current thread until it is available. /// /// Behavior is undefined if the mutex has been moved between this and any /// previous function call. #[inline] pub unsafe fn lock(&self) { self.0.lock() } - /// Attempt to lock the mutex without blocking, returning whether it was + /// Attempts to lock the mutex without blocking, returning whether it was /// successfully acquired or not. /// /// Behavior is undefined if the mutex has been moved between this and any @@ -39,14 +39,14 @@ impl Mutex { #[inline] pub unsafe fn try_lock(&self) -> bool { self.0.try_lock() } - /// Unlock the mutex. + /// Unlocks the mutex. /// /// Behavior is undefined if the current thread does not actually hold the /// mutex. #[inline] pub unsafe fn unlock(&self) { self.0.unlock() } - /// Deallocate all resources associated with this mutex. + /// Deallocates all resources associated with this mutex. /// /// Behavior is undefined if there are current or will be future users of /// this mutex. diff --git a/src/libstd/sys/common/poison.rs b/src/libstd/sys/common/poison.rs index 347cd0b464e..6deb4a48007 100644 --- a/src/libstd/sys/common/poison.rs +++ b/src/libstd/sys/common/poison.rs @@ -116,7 +116,7 @@ impl Error for PoisonError { } impl PoisonError { - /// Create a `PoisonError`. + /// Creates a `PoisonError`. #[unstable(feature = "std_misc")] pub fn new(guard: T) -> PoisonError { PoisonError { guard: guard } diff --git a/src/libstd/sys/common/rwlock.rs b/src/libstd/sys/common/rwlock.rs index f7d7a5715bc..725a09bcc86 100644 --- a/src/libstd/sys/common/rwlock.rs +++ b/src/libstd/sys/common/rwlock.rs @@ -21,7 +21,7 @@ pub struct RWLock(imp::RWLock); pub const RWLOCK_INIT: RWLock = RWLock(imp::RWLOCK_INIT); impl RWLock { - /// Acquire shared access to the underlying lock, blocking the current + /// Acquires shared access to the underlying lock, blocking the current /// thread to do so. /// /// Behavior is undefined if the rwlock has been moved between this and any @@ -29,7 +29,7 @@ impl RWLock { #[inline] pub unsafe fn read(&self) { self.0.read() } - /// Attempt to acquire shared access to this lock, returning whether it + /// Attempts to acquire shared access to this lock, returning whether it /// succeeded or not. /// /// This function does not block the current thread. @@ -39,7 +39,7 @@ impl RWLock { #[inline] pub unsafe fn try_read(&self) -> bool { self.0.try_read() } - /// Acquire write access to the underlying lock, blocking the current thread + /// Acquires write access to the underlying lock, blocking the current thread /// to do so. /// /// Behavior is undefined if the rwlock has been moved between this and any @@ -47,7 +47,7 @@ impl RWLock { #[inline] pub unsafe fn write(&self) { self.0.write() } - /// Attempt to acquire exclusive access to this lock, returning whether it + /// Attempts to acquire exclusive access to this lock, returning whether it /// succeeded or not. /// /// This function does not block the current thread. @@ -57,20 +57,20 @@ impl RWLock { #[inline] pub unsafe fn try_write(&self) -> bool { self.0.try_write() } - /// Unlock previously acquired shared access to this lock. + /// Unlocks previously acquired shared access to this lock. /// /// Behavior is undefined if the current thread does not have shared access. #[inline] pub unsafe fn read_unlock(&self) { self.0.read_unlock() } - /// Unlock previously acquired exclusive access to this lock. + /// Unlocks previously acquired exclusive access to this lock. /// /// Behavior is undefined if the current thread does not currently have /// exclusive access. #[inline] pub unsafe fn write_unlock(&self) { self.0.write_unlock() } - /// Destroy OS-related resources with this RWLock. + /// Destroys OS-related resources with this RWLock. /// /// Behavior is undefined if there are any currently active users of this /// lock. diff --git a/src/libstd/sys/common/thread_local.rs b/src/libstd/sys/common/thread_local.rs index 5995d7ac10f..618a389110a 100644 --- a/src/libstd/sys/common/thread_local.rs +++ b/src/libstd/sys/common/thread_local.rs @@ -207,7 +207,7 @@ impl StaticKey { } impl Key { - /// Create a new managed OS TLS key. + /// Creates a new managed OS TLS key. /// /// This key will be deallocated when the key falls out of scope. /// diff --git a/src/libstd/sys/common/wtf8.rs b/src/libstd/sys/common/wtf8.rs index 987a12293da..34a4a773f8e 100644 --- a/src/libstd/sys/common/wtf8.rs +++ b/src/libstd/sys/common/wtf8.rs @@ -69,7 +69,7 @@ impl fmt::Debug for CodePoint { } impl CodePoint { - /// Unsafely create a new `CodePoint` without checking the value. + /// Unsafely creates a new `CodePoint` without checking the value. /// /// Only use when `value` is known to be less than or equal to 0x10FFFF. #[inline] @@ -77,9 +77,9 @@ impl CodePoint { CodePoint { value: value } } - /// Create a new `CodePoint` if the value is a valid code point. + /// Creates a new `CodePoint` if the value is a valid code point. /// - /// Return `None` if `value` is above 0x10FFFF. + /// Returns `None` if `value` is above 0x10FFFF. #[inline] pub fn from_u32(value: u32) -> Option { match value { @@ -88,7 +88,7 @@ impl CodePoint { } } - /// Create a new `CodePoint` from a `char`. + /// Creates a new `CodePoint` from a `char`. /// /// Since all Unicode scalar values are code points, this always succeeds. #[inline] @@ -96,15 +96,15 @@ impl CodePoint { CodePoint { value: value as u32 } } - /// Return the numeric value of the code point. + /// Returns the numeric value of the code point. #[inline] pub fn to_u32(&self) -> u32 { self.value } - /// Optionally return a Unicode scalar value for the code point. + /// Optionally returns a Unicode scalar value for the code point. /// - /// Return `None` if the code point is a surrogate (from U+D800 to U+DFFF). + /// Returns `None` if the code point is a surrogate (from U+D800 to U+DFFF). #[inline] pub fn to_char(&self) -> Option { match self.value { @@ -113,9 +113,9 @@ impl CodePoint { } } - /// Return a Unicode scalar value for the code point. + /// Returns a Unicode scalar value for the code point. /// - /// Return `'\u{FFFD}'` (the replacement character “�”) + /// Returns `'\u{FFFD}'` (the replacement character “�”) /// if the code point is a surrogate (from U+D800 to U+DFFF). #[inline] pub fn to_char_lossy(&self) -> char { @@ -151,19 +151,19 @@ impl fmt::Debug for Wtf8Buf { } impl Wtf8Buf { - /// Create an new, empty WTF-8 string. + /// Creates an new, empty WTF-8 string. #[inline] pub fn new() -> Wtf8Buf { Wtf8Buf { bytes: Vec::new() } } - /// Create an new, empty WTF-8 string with pre-allocated capacity for `n` bytes. + /// Creates an new, empty WTF-8 string with pre-allocated capacity for `n` bytes. #[inline] pub fn with_capacity(n: usize) -> Wtf8Buf { Wtf8Buf { bytes: Vec::with_capacity(n) } } - /// Create a WTF-8 string from an UTF-8 `String`. + /// Creates a WTF-8 string from an UTF-8 `String`. /// /// This takes ownership of the `String` and does not copy. /// @@ -173,7 +173,7 @@ impl Wtf8Buf { Wtf8Buf { bytes: string.into_bytes() } } - /// Create a WTF-8 string from an UTF-8 `&str` slice. + /// Creates a WTF-8 string from an UTF-8 `&str` slice. /// /// This copies the content of the slice. /// @@ -183,7 +183,7 @@ impl Wtf8Buf { Wtf8Buf { bytes: <[_]>::to_vec(str.as_bytes()) } } - /// Create a WTF-8 string from a potentially ill-formed UTF-16 slice of 16-bit code units. + /// Creates a WTF-8 string from a potentially ill-formed UTF-16 slice of 16-bit code units. /// /// This is lossless: calling `.encode_wide()` on the resulting string /// will always return the original code units. @@ -319,7 +319,7 @@ impl Wtf8Buf { self.bytes.truncate(new_len) } - /// Consume the WTF-8 string and try to convert it to UTF-8. + /// Consumes the WTF-8 string and tries to convert it to UTF-8. /// /// This does not copy the data. /// @@ -333,7 +333,7 @@ impl Wtf8Buf { } } - /// Consume the WTF-8 string and convert it lossily to UTF-8. + /// Consumes the WTF-8 string and converts it lossily to UTF-8. /// /// This does not copy the data (but may overwrite parts of it in place). /// @@ -454,7 +454,7 @@ impl fmt::Debug for Wtf8 { } impl Wtf8 { - /// Create a WTF-8 slice from a UTF-8 `&str` slice. + /// Creates a WTF-8 slice from a UTF-8 `&str` slice. /// /// Since WTF-8 is a superset of UTF-8, this always succeeds. #[inline] @@ -462,13 +462,13 @@ impl Wtf8 { unsafe { mem::transmute(value.as_bytes()) } } - /// Return the length, in WTF-8 bytes. + /// Returns the length, in WTF-8 bytes. #[inline] pub fn len(&self) -> usize { self.bytes.len() } - /// Return the code point at `position` if it is in the ASCII range, + /// Returns the code point at `position` if it is in the ASCII range, /// or `b'\xFF' otherwise. /// /// # Panics @@ -482,7 +482,7 @@ impl Wtf8 { } } - /// Return the code point at `position`. + /// Returns the code point at `position`. /// /// # Panics /// @@ -494,7 +494,7 @@ impl Wtf8 { code_point } - /// Return the code point at `position` + /// Returns the code point at `position` /// and the position of the next code point. /// /// # Panics @@ -507,15 +507,15 @@ impl Wtf8 { (CodePoint { value: c }, n) } - /// Return an iterator for the string’s code points. + /// Returns an iterator for the string’s code points. #[inline] pub fn code_points(&self) -> Wtf8CodePoints { Wtf8CodePoints { bytes: self.bytes.iter() } } - /// Try to convert the string to UTF-8 and return a `&str` slice. + /// Tries to convert the string to UTF-8 and return a `&str` slice. /// - /// Return `None` if the string contains surrogates. + /// Returns `None` if the string contains surrogates. /// /// This does not copy the data. #[inline] @@ -528,8 +528,8 @@ impl Wtf8 { } } - /// Lossily convert the string to UTF-8. - /// Return an UTF-8 `&str` slice if the contents are well-formed in UTF-8. + /// Lossily converts the string to UTF-8. + /// Returns an UTF-8 `&str` slice if the contents are well-formed in UTF-8. /// /// Surrogates are replaced with `"\u{FFFD}"` (the replacement character “�”). /// @@ -559,7 +559,7 @@ impl Wtf8 { } } - /// Convert the WTF-8 string to potentially ill-formed UTF-16 + /// Converts the WTF-8 string to potentially ill-formed UTF-16 /// and return an iterator of 16-bit code units. /// /// This is lossless: diff --git a/src/libstd/sys/unix/ext.rs b/src/libstd/sys/unix/ext.rs index fbfbb40701f..a95cb85e74a 100644 --- a/src/libstd/sys/unix/ext.rs +++ b/src/libstd/sys/unix/ext.rs @@ -53,7 +53,7 @@ pub mod io { /// and `AsRawSocket` set of traits. #[stable(feature = "rust1", since = "1.0.0")] pub trait AsRawFd { - /// Extract the raw file descriptor. + /// Extracts the raw file descriptor. /// /// This method does **not** pass ownership of the raw file descriptor /// to the caller. The descriptor is only guarantee to be valid while @@ -216,11 +216,11 @@ pub mod ffi { /// Unix-specific extensions to `OsString`. #[stable(feature = "rust1", since = "1.0.0")] pub trait OsStringExt { - /// Create an `OsString` from a byte vector. + /// Creates an `OsString` from a byte vector. #[stable(feature = "rust1", since = "1.0.0")] fn from_vec(vec: Vec) -> Self; - /// Yield the underlying byte vector of this `OsString`. + /// Yields the underlying byte vector of this `OsString`. #[stable(feature = "rust1", since = "1.0.0")] fn into_vec(self) -> Vec; } @@ -241,7 +241,7 @@ pub mod ffi { #[stable(feature = "rust1", since = "1.0.0")] fn from_bytes(slice: &[u8]) -> &Self; - /// Get the underlying byte view of the `OsStr` slice. + /// Gets the underlying byte view of the `OsStr` slice. #[stable(feature = "rust1", since = "1.0.0")] fn as_bytes(&self) -> &[u8]; } @@ -280,7 +280,7 @@ pub mod fs { /// Unix-specific extensions to `OpenOptions` pub trait OpenOptionsExt { - /// Set the mode bits that a new file will be created with. + /// Sets the mode bits that a new file will be created with. /// /// If a new file is created as part of a `File::open_opts` call then this /// specified `mode` will be used as the permission bits for the new file. diff --git a/src/libstd/sys/unix/fd.rs b/src/libstd/sys/unix/fd.rs index d86c77624e8..e5bdb554359 100644 --- a/src/libstd/sys/unix/fd.rs +++ b/src/libstd/sys/unix/fd.rs @@ -28,7 +28,7 @@ impl FileDesc { pub fn raw(&self) -> c_int { self.fd } - /// Extract the actual filedescriptor without closing it. + /// Extracts the actual filedescriptor without closing it. pub fn into_raw(self) -> c_int { let fd = self.fd; unsafe { mem::forget(self) }; diff --git a/src/libstd/sys/unix/fs.rs b/src/libstd/sys/unix/fs.rs index 6121105f10b..c74d6b7e077 100644 --- a/src/libstd/sys/unix/fs.rs +++ b/src/libstd/sys/unix/fs.rs @@ -130,7 +130,7 @@ impl FileDesc { } } - /// Extract the actual filedescriptor without closing it. + /// Extracts the actual filedescriptor without closing it. pub fn unwrap(self) -> fd_t { let fd = self.fd; unsafe { mem::forget(self) }; diff --git a/src/libstd/sys/unix/mod.rs b/src/libstd/sys/unix/mod.rs index e8409bb4fd4..71da2f9219c 100644 --- a/src/libstd/sys/unix/mod.rs +++ b/src/libstd/sys/unix/mod.rs @@ -85,7 +85,7 @@ pub fn last_gai_error(s: libc::c_int) -> IoError { err } -/// Convert an `errno` value into a high-level error variant and description. +/// Converts an `errno` value into a high-level error variant and description. #[allow(deprecated)] pub fn decode_error(errno: i32) -> IoError { // FIXME: this should probably be a bit more descriptive... diff --git a/src/libstd/sys/unix/os.rs b/src/libstd/sys/unix/os.rs index d2220bdec32..52ec6063d7a 100644 --- a/src/libstd/sys/unix/os.rs +++ b/src/libstd/sys/unix/os.rs @@ -86,7 +86,7 @@ pub fn errno() -> i32 { } } -/// Get a detailed string description for the given error number +/// Gets a detailed string description for the given error number. pub fn error_string(errno: i32) -> String { #[cfg(target_os = "linux")] extern { diff --git a/src/libstd/sys/windows/ext.rs b/src/libstd/sys/windows/ext.rs index 2dd61861bd6..022407ebc02 100644 --- a/src/libstd/sys/windows/ext.rs +++ b/src/libstd/sys/windows/ext.rs @@ -38,7 +38,7 @@ pub mod io { /// Extract raw handles. #[stable(feature = "rust1", since = "1.0.0")] pub trait AsRawHandle { - /// Extract the raw handle, without taking any ownership. + /// Extracts the raw handle, without taking any ownership. #[stable(feature = "rust1", since = "1.0.0")] fn as_raw_handle(&self) -> RawHandle; } @@ -47,7 +47,7 @@ pub mod io { #[unstable(feature = "from_raw_os", reason = "recent addition to the std::os::windows::io module")] pub trait FromRawHandle { - /// Construct a new I/O object from the specified raw handle. + /// Constructs a new I/O object from the specified raw handle. /// /// This function will **consume ownership** of the handle given, /// passing responsibility for closing the handle to the returned @@ -112,7 +112,7 @@ pub mod io { /// Extract raw sockets. #[stable(feature = "rust1", since = "1.0.0")] pub trait AsRawSocket { - /// Extract the underlying raw socket from this object. + /// Extracts the underlying raw socket from this object. #[stable(feature = "rust1", since = "1.0.0")] fn as_raw_socket(&self) -> RawSocket; } @@ -214,7 +214,7 @@ pub mod ffi { /// Windows-specific extensions to `OsString`. #[stable(feature = "rust1", since = "1.0.0")] pub trait OsStringExt { - /// Create an `OsString` from a potentially ill-formed UTF-16 slice of + /// Creates an `OsString` from a potentially ill-formed UTF-16 slice of /// 16-bit code units. /// /// This is lossless: calling `.encode_wide()` on the resulting string @@ -233,7 +233,7 @@ pub mod ffi { /// Windows-specific extensions to `OsStr`. #[stable(feature = "rust1", since = "1.0.0")] pub trait OsStrExt { - /// Re-encode an `OsStr` as a wide character sequence, + /// Re-encodes an `OsStr` as a wide character sequence, /// i.e. potentially ill-formed UTF-16. /// /// This is lossless. Note that the encoding does not include a final @@ -258,25 +258,25 @@ pub mod fs { /// Windows-specific extensions to `OpenOptions` pub trait OpenOptionsExt { - /// Override the `dwDesiredAccess` argument to the call to `CreateFile` + /// Overrides the `dwDesiredAccess` argument to the call to `CreateFile` /// with the specified value. fn desired_access(&mut self, access: i32) -> &mut Self; - /// Override the `dwCreationDisposition` argument to the call to + /// Overrides the `dwCreationDisposition` argument to the call to /// `CreateFile` with the specified value. /// /// This will override any values of the standard `create` flags, for /// example. fn creation_disposition(&mut self, val: i32) -> &mut Self; - /// Override the `dwFlagsAndAttributes` argument to the call to + /// Overrides the `dwFlagsAndAttributes` argument to the call to /// `CreateFile` with the specified value. /// /// This will override any values of the standard flags on the /// `OpenOptions` structure. fn flags_and_attributes(&mut self, val: i32) -> &mut Self; - /// Override the `dwShareMode` argument to the call to `CreateFile` with + /// Overrides the `dwShareMode` argument to the call to `CreateFile` with /// the specified value. /// /// This will override any values of the standard flags on the diff --git a/src/libstd/sys/windows/mod.rs b/src/libstd/sys/windows/mod.rs index e9d5fca531f..eb031e9b745 100644 --- a/src/libstd/sys/windows/mod.rs +++ b/src/libstd/sys/windows/mod.rs @@ -95,7 +95,7 @@ pub fn last_gai_error(_errno: i32) -> IoError { last_net_error() } -/// Convert an `errno` value into a high-level error variant and description. +/// Converts an `errno` value into a high-level error variant and description. #[allow(deprecated)] pub fn decode_error(errno: i32) -> IoError { let (kind, desc) = match errno { diff --git a/src/libstd/sys/windows/os.rs b/src/libstd/sys/windows/os.rs index d5843a2f998..232e5669c2b 100644 --- a/src/libstd/sys/windows/os.rs +++ b/src/libstd/sys/windows/os.rs @@ -42,7 +42,7 @@ pub fn errno() -> i32 { unsafe { libc::GetLastError() as i32 } } -/// Get a detailed string description for the given error number +/// Gets a detailed string description for the given error number. pub fn error_string(errnum: i32) -> String { use libc::types::os::arch::extra::DWORD; use libc::types::os::arch::extra::LPWSTR; diff --git a/src/libstd/thread/local.rs b/src/libstd/thread/local.rs index f5a1093be2b..cc4031cc180 100644 --- a/src/libstd/thread/local.rs +++ b/src/libstd/thread/local.rs @@ -226,7 +226,7 @@ pub enum LocalKeyState { } impl LocalKey { - /// Acquire a reference to the value in this TLS key. + /// Acquires a reference to the value in this TLS key. /// /// This will lazily initialize the value if this thread has not referenced /// this key yet. diff --git a/src/libstd/thread/mod.rs b/src/libstd/thread/mod.rs index 0e5fee27ffe..5db7e9773c9 100644 --- a/src/libstd/thread/mod.rs +++ b/src/libstd/thread/mod.rs @@ -215,7 +215,7 @@ pub struct Builder { } impl Builder { - /// Generate the base configuration for spawning a thread, from which + /// Generates the base configuration for spawning a thread, from which /// configuration methods can be chained. #[stable(feature = "rust1", since = "1.0.0")] pub fn new() -> Builder { @@ -225,7 +225,7 @@ impl Builder { } } - /// Name the thread-to-be. Currently the name is used for identification + /// Names the thread-to-be. Currently the name is used for identification /// only in panic messages. #[stable(feature = "rust1", since = "1.0.0")] pub fn name(mut self, name: String) -> Builder { @@ -233,14 +233,14 @@ impl Builder { self } - /// Set the size of the stack for the new thread. + /// Sets the size of the stack for the new thread. #[stable(feature = "rust1", since = "1.0.0")] pub fn stack_size(mut self, size: usize) -> Builder { self.stack_size = Some(size); self } - /// Spawn a new thread, and return a join handle for it. + /// Spawns a new thread, and returns a join handle for it. /// /// The child thread may outlive the parent (unless the parent thread /// is the main thread; the whole process is terminated when the main @@ -259,8 +259,8 @@ impl Builder { self.spawn_inner(Box::new(f)).map(|i| JoinHandle(i)) } - /// Spawn a new child thread that must be joined within a given - /// scope, and return a `JoinGuard`. + /// Spawns a new child thread that must be joined within a given + /// scope, and returns a `JoinGuard`. /// /// The join guard can be used to explicitly join the child thread (via /// `join`), returning `Result`, or it will implicitly join the child @@ -355,7 +355,7 @@ impl Builder { // Free functions //////////////////////////////////////////////////////////////////////////////// -/// Spawn a new thread, returning a `JoinHandle` for it. +/// Spawns a new thread, returning a `JoinHandle` for it. /// /// The join handle will implicitly *detach* the child thread upon being /// dropped. In this case, the child thread may outlive the parent (unless @@ -374,7 +374,7 @@ pub fn spawn(f: F) -> JoinHandle where F: FnOnce(), F: Send + 'static { Builder::new().spawn(f).unwrap() } -/// Spawn a new *scoped* thread, returning a `JoinGuard` for it. +/// Spawns a new *scoped* thread, returning a `JoinGuard` for it. /// /// The join guard can be used to explicitly join the child thread (via /// `join`), returning `Result`, or it will implicitly join the child @@ -400,7 +400,7 @@ pub fn current() -> Thread { thread_info::current_thread() } -/// Cooperatively give up a timeslice to the OS scheduler. +/// Cooperatively gives up a timeslice to the OS scheduler. #[stable(feature = "rust1", since = "1.0.0")] pub fn yield_now() { unsafe { imp::yield_now() } @@ -413,7 +413,7 @@ pub fn panicking() -> bool { unwind::panicking() } -/// Invoke a closure, capturing the cause of panic if one occurs. +/// Invokes a closure, capturing the cause of panic if one occurs. /// /// This function will return `Ok(())` if the closure does not panic, and will /// return `Err(cause)` if the closure panics. The `cause` returned is the @@ -462,7 +462,7 @@ pub fn catch_panic(f: F) -> Result Ok(result.unwrap()) } -/// Put the current thread to sleep for the specified amount of time. +/// Puts the current thread to sleep for the specified amount of time. /// /// The thread may sleep longer than the duration specified due to scheduling /// specifics or platform-dependent functionality. Note that on unix platforms @@ -482,7 +482,7 @@ pub fn sleep(dur: Duration) { imp::sleep(dur) } -/// Block unless or until the current thread's token is made available (may wake spuriously). +/// Blocks unless or until the current thread's token is made available (may wake spuriously). /// /// See the module doc for more detail. // @@ -501,7 +501,7 @@ pub fn park() { *guard = false; } -/// Block unless or until the current thread's token is made available or +/// Blocks unless or until the current thread's token is made available or /// the specified duration has been reached (may wake spuriously). /// /// The semantics of this function are equivalent to `park()` except that the @@ -573,7 +573,7 @@ impl Thread { } } - /// Get the thread's name. + /// Gets the thread's name. #[stable(feature = "rust1", since = "1.0.0")] pub fn name(&self) -> Option<&str> { self.inner.name.as_ref().map(|s| &**s) @@ -638,13 +638,13 @@ impl JoinInner { pub struct JoinHandle(JoinInner<()>); impl JoinHandle { - /// Extract a handle to the underlying thread + /// Extracts a handle to the underlying thread #[stable(feature = "rust1", since = "1.0.0")] pub fn thread(&self) -> &Thread { &self.0.thread } - /// Wait for the associated thread to finish. + /// Waits for the associated thread to finish. /// /// If the child thread panics, `Err` is returned with the parameter given /// to `panic`. @@ -684,13 +684,13 @@ pub struct JoinGuard<'a, T: Send + 'a> { unsafe impl<'a, T: Send + 'a> Sync for JoinGuard<'a, T> {} impl<'a, T: Send + 'a> JoinGuard<'a, T> { - /// Extract a handle to the thread this guard will join on. + /// Extracts a handle to the thread this guard will join on. #[stable(feature = "rust1", since = "1.0.0")] pub fn thread(&self) -> &Thread { &self.inner.thread } - /// Wait for the associated thread to finish, returning the result of the + /// Waits for the associated thread to finish, returning the result of the /// thread's calculation. /// /// # Panics diff --git a/src/libstd/thread/scoped_tls.rs b/src/libstd/thread/scoped_tls.rs index fa980954c2f..9c0b4a5d833 100644 --- a/src/libstd/thread/scoped_tls.rs +++ b/src/libstd/thread/scoped_tls.rs @@ -135,7 +135,7 @@ macro_rules! __scoped_thread_local_inner { reason = "scoped TLS has yet to have wide enough use to fully consider \ stabilizing its interface")] impl ScopedKey { - /// Insert a value into this scoped thread local storage slot for a + /// Inserts a value into this scoped thread local storage slot for a /// duration of a closure. /// /// While `cb` is running, the value `t` will be returned by `get` unless @@ -188,7 +188,7 @@ impl ScopedKey { cb() } - /// Get a value out of this scoped variable. + /// Gets a value out of this scoped variable. /// /// This function takes a closure which receives the value of this /// variable. -- cgit 1.4.1-3-g733a5 From 8f7eb3b058f78bffe5406776eb31080615799ce7 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Fri, 10 Apr 2015 13:23:17 -0700 Subject: core: Update all Result docs --- src/libcore/result.rs | 122 +++++++++++++++++++++----------------------------- 1 file changed, 52 insertions(+), 70 deletions(-) (limited to 'src/libcore') diff --git a/src/libcore/result.rs b/src/libcore/result.rs index 67a5ab891f7..66c68631491 100644 --- a/src/libcore/result.rs +++ b/src/libcore/result.rs @@ -85,35 +85,32 @@ //! functions that may encounter errors but don't otherwise return a //! useful value. //! -//! Consider the `write_line` method defined for I/O types -//! by the [`Writer`](../old_io/trait.Writer.html) trait: +//! Consider the `write_all` method defined for I/O types +//! by the [`Write`](../io/trait.Write.html) trait: //! //! ``` -//! # #![feature(old_io)] -//! use std::old_io::IoError; +//! use std::io; //! //! trait Writer { -//! fn write_line(&mut self, s: &str) -> Result<(), IoError>; +//! fn write_all(&mut self, bytes: &[u8]) -> Result<(), io::Error>; //! } //! ``` //! -//! *Note: The actual definition of `Writer` uses `IoResult`, which -//! is just a synonym for `Result`.* +//! *Note: The actual definition of `Write` uses `io::Result`, which +//! is just a synonym for `Result`.* //! //! This method doesn't produce a value, but the write may //! fail. It's crucial to handle the error case, and *not* write //! something like this: //! -//! ```{.ignore} -//! # #![feature(old_io)] -//! use std::old_io::*; -//! use std::old_path::Path; +//! ```no_run +//! use std::fs::File; +//! use std::io::prelude::*; //! -//! let mut file = File::open_mode(&Path::new("valuable_data.txt"), Open, Write); -//! // If `write_line` errors, then we'll never know, because the return +//! let mut file = File::create("valuable_data.txt").unwrap(); +//! // If `write_all` errors, then we'll never know, because the return //! // value is ignored. -//! file.write_line("important message"); -//! drop(file); +//! file.write_all(b"important message"); //! ``` //! //! If you *do* write that in Rust, the compiler will give you a @@ -125,37 +122,31 @@ //! a marginally useful message indicating why: //! //! ```{.no_run} -//! # #![feature(old_io, old_path)] -//! use std::old_io::*; -//! use std::old_path::Path; +//! use std::fs::File; +//! use std::io::prelude::*; //! -//! let mut file = File::open_mode(&Path::new("valuable_data.txt"), Open, Write); -//! file.write_line("important message").ok().expect("failed to write message"); -//! drop(file); +//! let mut file = File::create("valuable_data.txt").unwrap(); +//! file.write_all(b"important message").ok().expect("failed to write message"); //! ``` //! //! You might also simply assert success: //! //! ```{.no_run} -//! # #![feature(old_io, old_path)] -//! # use std::old_io::*; -//! # use std::old_path::Path; -//! -//! # let mut file = File::open_mode(&Path::new("valuable_data.txt"), Open, Write); -//! assert!(file.write_line("important message").is_ok()); -//! # drop(file); +//! # use std::fs::File; +//! # use std::io::prelude::*; +//! # let mut file = File::create("valuable_data.txt").unwrap(); +//! assert!(file.write_all(b"important message").is_ok()); //! ``` //! //! Or propagate the error up the call stack with `try!`: //! //! ``` -//! # #![feature(old_io, old_path)] -//! # use std::old_io::*; -//! # use std::old_path::Path; -//! fn write_message() -> Result<(), IoError> { -//! let mut file = File::open_mode(&Path::new("valuable_data.txt"), Open, Write); -//! try!(file.write_line("important message")); -//! drop(file); +//! # use std::fs::File; +//! # use std::io::prelude::*; +//! # use std::io; +//! fn write_message() -> io::Result<()> { +//! let mut file = try!(File::create("valuable_data.txt")); +//! try!(file.write_all(b"important message")); //! Ok(()) //! } //! ``` @@ -170,9 +161,9 @@ //! It replaces this: //! //! ``` -//! # #![feature(old_io, old_path)] -//! use std::old_io::*; -//! use std::old_path::Path; +//! use std::fs::File; +//! use std::io::prelude::*; +//! use std::io; //! //! struct Info { //! name: String, @@ -180,25 +171,28 @@ //! rating: i32, //! } //! -//! fn write_info(info: &Info) -> Result<(), IoError> { -//! let mut file = File::open_mode(&Path::new("my_best_friends.txt"), Open, Write); +//! fn write_info(info: &Info) -> io::Result<()> { +//! let mut file = try!(File::create("my_best_friends.txt")); //! // Early return on error -//! if let Err(e) = file.write_line(&format!("name: {}", info.name)) { +//! if let Err(e) = file.write_all(format!("name: {}\n", info.name).as_bytes()) { +//! return Err(e) +//! } +//! if let Err(e) = file.write_all(format!("age: {}\n", info.age).as_bytes()) { //! return Err(e) //! } -//! if let Err(e) = file.write_line(&format!("age: {}", info.age)) { +//! if let Err(e) = file.write_all(format!("rating: {}\n", info.rating).as_bytes()) { //! return Err(e) //! } -//! file.write_line(&format!("rating: {}", info.rating)) +//! Ok(()) //! } //! ``` //! //! With this: //! //! ``` -//! # #![feature(old_io, old_path)] -//! use std::old_io::*; -//! use std::old_path::Path; +//! use std::fs::File; +//! use std::io::prelude::*; +//! use std::io; //! //! struct Info { //! name: String, @@ -206,12 +200,12 @@ //! rating: i32, //! } //! -//! fn write_info(info: &Info) -> Result<(), IoError> { -//! let mut file = File::open_mode(&Path::new("my_best_friends.txt"), Open, Write); +//! fn write_info(info: &Info) -> io::Result<()> { +//! let mut file = try!(File::create("my_best_friends.txt")); //! // Early return on error -//! try!(file.write_line(&format!("name: {}", info.name))); -//! try!(file.write_line(&format!("age: {}", info.age))); -//! try!(file.write_line(&format!("rating: {}", info.rating))); +//! try!(file.write_all(format!("name: {}\n", info.name).as_bytes())); +//! try!(file.write_all(format!("age: {}\n", info.age).as_bytes())); +//! try!(file.write_all(format!("rating: {}\n", info.rating).as_bytes())); //! Ok(()) //! } //! ``` @@ -464,29 +458,17 @@ impl Result { /// /// # Examples /// - /// Sum the lines of a buffer by mapping strings to numbers, - /// ignoring I/O and parse errors: + /// Print the numbers on each line of a string multiplied by two. /// /// ``` - /// # #![feature(old_io)] - /// use std::old_io::*; + /// let line = "1\n2\n3\n4\n"; /// - /// let mut buffer: &[u8] = b"1\n2\n3\n4\n"; - /// let mut buffer = &mut buffer; - /// - /// let mut sum = 0; - /// - /// while !buffer.is_empty() { - /// let line: IoResult = buffer.read_line(); - /// // Convert the string line to a number using `map` and `from_str` - /// let val: IoResult = line.map(|line| { - /// line.trim_right().parse::().unwrap_or(0) - /// }); - /// // Add the value if there were no errors, otherwise add 0 - /// sum += val.unwrap_or(0); + /// for num in line.lines() { + /// match num.parse::().map(|i| i * 2) { + /// Ok(n) => println!("{}", n), + /// Err(..) => {} + /// } /// } - /// - /// assert!(sum == 10); /// ``` #[inline] #[stable(feature = "rust1", since = "1.0.0")] -- cgit 1.4.1-3-g733a5