time: document return type of timeout (#5118)

This commit is contained in:
Alice Ryhl 2022-10-22 19:23:40 +02:00 committed by GitHub
parent a03e042024
commit d32ba2cf9d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 4 deletions

View File

@ -41,6 +41,9 @@ impl From<Kind> for Error {
} }
/// Errors returned by `Timeout`. /// Errors returned by `Timeout`.
///
/// This error is returned when a timeout expires before the function was able
/// to finish.
#[derive(Debug, PartialEq)] #[derive(Debug, PartialEq)]
pub struct Elapsed(()); pub struct Elapsed(());

View File

@ -21,6 +21,12 @@ use std::task::{self, Poll};
/// value is returned. Otherwise, an error is returned and the future is /// value is returned. Otherwise, an error is returned and the future is
/// canceled. /// canceled.
/// ///
/// This function returns a future whose return type is [`Result`]`<T,`[`Elapsed`]`>`, where `T` is the
/// return type of the provided future.
///
/// [`Result`]: std::result::Result
/// [`Elapsed`]: crate::time::error::Elapsed
///
/// # Cancellation /// # Cancellation
/// ///
/// Cancelling a timeout is done by dropping the future. No additional cleanup /// Cancelling a timeout is done by dropping the future. No additional cleanup
@ -68,9 +74,9 @@ use std::task::{self, Poll};
/// [`Builder::enable_time`]: crate::runtime::Builder::enable_time /// [`Builder::enable_time`]: crate::runtime::Builder::enable_time
/// [`Builder::enable_all`]: crate::runtime::Builder::enable_all /// [`Builder::enable_all`]: crate::runtime::Builder::enable_all
#[track_caller] #[track_caller]
pub fn timeout<T>(duration: Duration, future: T) -> Timeout<T> pub fn timeout<F>(duration: Duration, future: F) -> Timeout<F>
where where
T: Future, F: Future,
{ {
let location = trace::caller_location(); let location = trace::caller_location();
@ -87,6 +93,12 @@ where
/// If the future completes before the instant is reached, then the completed /// If the future completes before the instant is reached, then the completed
/// value is returned. Otherwise, an error is returned. /// value is returned. Otherwise, an error is returned.
/// ///
/// This function returns a future whose return type is [`Result`]`<T,`[`Elapsed`]`>`, where `T` is the
/// return type of the provided future.
///
/// [`Result`]: std::result::Result
/// [`Elapsed`]: crate::time::error::Elapsed
///
/// # Cancellation /// # Cancellation
/// ///
/// Cancelling a timeout is done by dropping the future. No additional cleanup /// Cancelling a timeout is done by dropping the future. No additional cleanup
@ -116,9 +128,9 @@ where
/// } /// }
/// # } /// # }
/// ``` /// ```
pub fn timeout_at<T>(deadline: Instant, future: T) -> Timeout<T> pub fn timeout_at<F>(deadline: Instant, future: F) -> Timeout<F>
where where
T: Future, F: Future,
{ {
let delay = sleep_until(deadline); let delay = sleep_until(deadline);