Step in core::iter - Rust (original) (raw)

pub trait Step:
    Clone
    + PartialOrd
    + Sized {
    // Required methods
    fn steps_between(start: &Self, end: &Self) -> (usize, Option<usize>);
    fn forward_checked(start: Self, count: usize) -> Option<Self>;
    fn backward_checked(start: Self, count: usize) -> Option<Self>;

    // Provided methods
    fn forward(start: Self, count: usize) -> Self { ... }
    unsafe fn forward_unchecked(start: Self, count: usize) -> Self { ... }
    fn backward(start: Self, count: usize) -> Self { ... }
    unsafe fn backward_unchecked(start: Self, count: usize) -> Self { ... }
}

🔬This is a nightly-only experimental API. (step_trait #42168)

Expand description

Objects that have a notion of successor and predecessor operations.

The successor operation moves towards values that compare greater. The predecessor operation moves towards values that compare lesser.

Source

🔬This is a nightly-only experimental API. (step_trait #42168)

Returns the bounds on the number of successor steps required to get from start to endlike Iterator::size_hint().

Returns (usize::MAX, None) if the number of steps would overflow usize, or is infinite.

§Invariants

For any a, b, and n:

Source

🔬This is a nightly-only experimental API. (step_trait #42168)

Returns the value that would be obtained by taking the _successor_of self count times.

If this would overflow the range of values supported by Self, returns None.

§Invariants

For any a, n, and m:

For any a and n:

Source

🔬This is a nightly-only experimental API. (step_trait #42168)

Returns the value that would be obtained by taking the _predecessor_of self count times.

If this would overflow the range of values supported by Self, returns None.

§Invariants

For any a, n, and m:

For any a and n:

Source

🔬This is a nightly-only experimental API. (step_trait #42168)

Returns the value that would be obtained by taking the _successor_of self count times.

If this would overflow the range of values supported by Self, this function is allowed to panic, wrap, or saturate. The suggested behavior is to panic when debug assertions are enabled, and to wrap or saturate otherwise.

Unsafe code should not rely on the correctness of behavior after overflow.

§Invariants

For any a, n, and m, where no overflow occurs:

For any a and n, where no overflow occurs:

Source

🔬This is a nightly-only experimental API. (step_trait #42168)

Returns the value that would be obtained by taking the _successor_of self count times.

§Safety

It is undefined behavior for this operation to overflow the range of values supported by Self. If you cannot guarantee that this will not overflow, use forward or forward_checked instead.

§Invariants

For any a:

For any a and n, where no overflow occurs:

Source

🔬This is a nightly-only experimental API. (step_trait #42168)

Returns the value that would be obtained by taking the _predecessor_of self count times.

If this would overflow the range of values supported by Self, this function is allowed to panic, wrap, or saturate. The suggested behavior is to panic when debug assertions are enabled, and to wrap or saturate otherwise.

Unsafe code should not rely on the correctness of behavior after overflow.

§Invariants

For any a, n, and m, where no overflow occurs:

For any a and n, where no overflow occurs:

Source

🔬This is a nightly-only experimental API. (step_trait #42168)

Returns the value that would be obtained by taking the _predecessor_of self count times.

§Safety

It is undefined behavior for this operation to overflow the range of values supported by Self. If you cannot guarantee that this will not overflow, use backward or backward_checked instead.

§Invariants

For any a:

For any a and n, where no overflow occurs:

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Source§

Source§

Source§

Source§

Source§

Source§

Source§

Source§

Source§

Source§

Source§

Source§

Source§

Source§

Source§

Source§