mirror of
https://github.com/rust-lang/rust.git
synced 2025-01-26 22:53:28 +00:00
Improve Step docs
This commit is contained in:
parent
e61dcc7a0a
commit
c527ec76ce
@ -22,7 +22,7 @@ unsafe_impl_trusted_step![AsciiChar char i8 i16 i32 i64 i128 isize u8 u16 u32 u6
|
||||
///
|
||||
/// The *successor* operation moves towards values that compare greater.
|
||||
/// The *predecessor* operation moves towards values that compare lesser.
|
||||
#[unstable(feature = "step_trait", reason = "recently redesigned", issue = "42168")]
|
||||
#[unstable(feature = "step_trait", issue = "42168")]
|
||||
pub trait Step: Clone + PartialOrd + Sized {
|
||||
/// Returns the number of *successor* steps required to get from `start` to `end`.
|
||||
///
|
||||
@ -52,15 +52,12 @@ pub trait Step: Clone + PartialOrd + Sized {
|
||||
/// For any `a`, `n`, and `m`:
|
||||
///
|
||||
/// * `Step::forward_checked(a, n).and_then(|x| Step::forward_checked(x, m)) == Step::forward_checked(a, m).and_then(|x| Step::forward_checked(x, n))`
|
||||
///
|
||||
/// For any `a`, `n`, and `m` where `n + m` does not overflow:
|
||||
///
|
||||
/// * `Step::forward_checked(a, n).and_then(|x| Step::forward_checked(x, m)) == Step::forward_checked(a, n + m)`
|
||||
/// * `Step::forward_checked(a, n).and_then(|x| Step::forward_checked(x, m)) == try { Step::forward_checked(a, n.checked_add(m)) }`
|
||||
///
|
||||
/// For any `a` and `n`:
|
||||
///
|
||||
/// * `Step::forward_checked(a, n) == (0..n).try_fold(a, |x, _| Step::forward_checked(&x, 1))`
|
||||
/// * Corollary: `Step::forward_checked(&a, 0) == Some(a)`
|
||||
/// * Corollary: `Step::forward_checked(a, 0) == Some(a)`
|
||||
fn forward_checked(start: Self, count: usize) -> Option<Self>;
|
||||
|
||||
/// Returns the value that would be obtained by taking the *successor*
|
||||
@ -106,6 +103,7 @@ pub trait Step: Clone + PartialOrd + Sized {
|
||||
/// * if there exists `b` such that `b > a`, it is safe to call `Step::forward_unchecked(a, 1)`
|
||||
/// * if there exists `b`, `n` such that `steps_between(&a, &b) == Some(n)`,
|
||||
/// it is safe to call `Step::forward_unchecked(a, m)` for any `m <= n`.
|
||||
/// * Corollary: `Step::forward_unchecked(a, 0)` is always safe.
|
||||
///
|
||||
/// For any `a` and `n`, where no overflow occurs:
|
||||
///
|
||||
@ -128,8 +126,8 @@ pub trait Step: Clone + PartialOrd + Sized {
|
||||
///
|
||||
/// For any `a` and `n`:
|
||||
///
|
||||
/// * `Step::backward_checked(a, n) == (0..n).try_fold(a, |x, _| Step::backward_checked(&x, 1))`
|
||||
/// * Corollary: `Step::backward_checked(&a, 0) == Some(a)`
|
||||
/// * `Step::backward_checked(a, n) == (0..n).try_fold(a, |x, _| Step::backward_checked(x, 1))`
|
||||
/// * Corollary: `Step::backward_checked(a, 0) == Some(a)`
|
||||
fn backward_checked(start: Self, count: usize) -> Option<Self>;
|
||||
|
||||
/// Returns the value that would be obtained by taking the *predecessor*
|
||||
@ -175,6 +173,7 @@ pub trait Step: Clone + PartialOrd + Sized {
|
||||
/// * if there exists `b` such that `b < a`, it is safe to call `Step::backward_unchecked(a, 1)`
|
||||
/// * if there exists `b`, `n` such that `steps_between(&b, &a) == Some(n)`,
|
||||
/// it is safe to call `Step::backward_unchecked(a, m)` for any `m <= n`.
|
||||
/// * Corollary: `Step::backward_unchecked(a, 0)` is always safe.
|
||||
///
|
||||
/// For any `a` and `n`, where no overflow occurs:
|
||||
///
|
||||
|
Loading…
Reference in New Issue
Block a user