diff options
| author | bors <bors@rust-lang.org> | 2017-05-03 23:05:07 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2017-05-03 23:05:07 +0000 |
| commit | b16c7a235fa0f57fed6b7ec13ffd3cff1bcdd9ad (patch) | |
| tree | e8fa6a2c0127f43d06a1e4fe7788c3cce852fab0 /src/libstd | |
| parent | 2d4ed8e0cbe2c5f3763273a5d8f6b15119473ba7 (diff) | |
| parent | e20b2823303ddb145ce58286abeb67d4c017ccf0 (diff) | |
| download | rust-b16c7a235fa0f57fed6b7ec13ffd3cff1bcdd9ad.tar.gz rust-b16c7a235fa0f57fed6b7ec13ffd3cff1bcdd9ad.zip | |
Auto merge of #41735 - frewsxcv:rollup, r=frewsxcv
Rollup of 6 pull requests - Successful merges: #41543, #41600, #41715, #41720, #41721, #41730 - Failed merges:
Diffstat (limited to 'src/libstd')
| -rw-r--r-- | src/libstd/process.rs | 10 | ||||
| -rw-r--r-- | src/libstd/thread/mod.rs | 33 | ||||
| -rw-r--r-- | src/libstd/time/duration.rs | 29 |
3 files changed, 53 insertions, 19 deletions
diff --git a/src/libstd/process.rs b/src/libstd/process.rs index 23ebeb4b8e3..3896fc20a2d 100644 --- a/src/libstd/process.rs +++ b/src/libstd/process.rs @@ -148,8 +148,9 @@ impl fmt::Debug for Child { } } -/// A handle to a child process's stdin. This struct is used in the [`stdin`] -/// field on [`Child`]. +/// A handle to a child process's stdin. +/// +/// This struct is used in the [`stdin`] field on [`Child`]. /// /// [`Child`]: struct.Child.html /// [`stdin`]: struct.Child.html#structfield.stdin @@ -190,8 +191,9 @@ impl fmt::Debug for ChildStdin { } } -/// A handle to a child process's stdout. This struct is used in the [`stdout`] -/// field on [`Child`]. +/// A handle to a child process's stdout. +/// +/// This struct is used in the [`stdout`] field on [`Child`]. /// /// [`Child`]: struct.Child.html /// [`stdout`]: struct.Child.html#structfield.stdout diff --git a/src/libstd/thread/mod.rs b/src/libstd/thread/mod.rs index e37cc7e963e..4e49c485f10 100644 --- a/src/libstd/thread/mod.rs +++ b/src/libstd/thread/mod.rs @@ -715,21 +715,32 @@ struct Inner { #[stable(feature = "rust1", since = "1.0.0")] /// A handle to a thread. /// +/// You can use it to identify a thread (by name, for example). Most of the +/// time, there is no need to directly create a `Thread` struct using the +/// constructor, instead you should use a function like `spawn` to create +/// new threads, see the docs of [`Builder`] and [`spawn`] for more. +/// /// # Examples /// /// ``` -/// use std::thread; -/// -/// let handler = thread::Builder::new() -/// .name("foo".into()) -/// .spawn(|| { -/// let thread = thread::current(); -/// println!("thread name: {}", thread.name().unwrap()); -/// }) -/// .unwrap(); -/// -/// handler.join().unwrap(); +/// use std::thread::Builder; +/// +/// for i in 0..5 { +/// let thread_name = format!("thread_{}", i); +/// Builder::new() +/// .name(thread_name) // Now you can identify which thread panicked +/// // thanks to the handle's name +/// .spawn(move || { +/// if i == 3 { +/// panic!("I'm scared!!!"); +/// } +/// }) +/// .unwrap(); +/// } /// ``` +/// [`Builder`]: ../../std/thread/struct.Builder.html +/// [`spawn`]: ../../std/thread/fn.spawn.html + pub struct Thread { inner: Arc<Inner>, } diff --git a/src/libstd/time/duration.rs b/src/libstd/time/duration.rs index af7eaeb3106..55766ba3fed 100644 --- a/src/libstd/time/duration.rs +++ b/src/libstd/time/duration.rs @@ -84,7 +84,10 @@ impl Duration { /// ``` /// use std::time::Duration; /// - /// let five_seconds = Duration::from_secs(5); + /// let duration = Duration::from_secs(5); + /// + /// assert_eq!(5, duration.as_secs()); + /// assert_eq!(0, duration.subsec_nanos()); /// ``` #[stable(feature = "duration", since = "1.3.0")] #[inline] @@ -99,7 +102,10 @@ impl Duration { /// ``` /// use std::time::Duration; /// - /// let five_seconds = Duration::from_millis(5000); + /// let duration = Duration::from_millis(2569); + /// + /// assert_eq!(2, duration.as_secs()); + /// assert_eq!(569000000, duration.subsec_nanos()); /// ``` #[stable(feature = "duration", since = "1.3.0")] #[inline] @@ -119,9 +125,24 @@ impl Duration { /// ``` /// use std::time::Duration; /// - /// let five_seconds = Duration::new(5, 0); - /// assert_eq!(five_seconds.as_secs(), 5); + /// let duration = Duration::new(5, 730023852); + /// assert_eq!(duration.as_secs(), 5); + /// ``` + /// + /// To determine the total number of seconds represented by the `Duration`, + /// use `as_secs` in combination with [`subsec_nanos`]: + /// /// ``` + /// use std::time::Duration; + /// + /// let duration = Duration::new(5, 730023852); + /// + /// assert_eq!(5.730023852, + /// duration.as_secs() as f64 + /// + duration.subsec_nanos() as f64 * 1e-9); + /// ``` + /// + /// [`subsec_nanos`]: #method.subsec_nanos #[stable(feature = "duration", since = "1.3.0")] #[inline] pub fn as_secs(&self) -> u64 { self.secs } |
