[][src]Function float_duration::iter::subdivide

Important traits for Subdivide
pub fn subdivide(
    begin: FloatDuration,
    end: FloatDuration,
    steps: usize
) -> Subdivide

Subdivide the distance between two duration into steps evenly spaced points.

subdivide returns an iterator that lazily computes and returns exactly steps evenly spaced points between begin and end. This iterator is inclusive in that it returns begin as the first element and end as the final element.

The returned iterator Subdivide implements DoubleEndedIterator, and thus can be reversed or consumed from both sides.

use float_duration::FloatDuration;
use float_duration::iter::subdivide;

fn cost_function(t: &FloatDuration) -> f64 {
    return 0.5*t.as_seconds()*t.as_seconds()
}
fn main() {
    let start = FloatDuration::zero();
    let end = FloatDuration::minutes(10.0);
    let total: f64 = subdivide(start, end, 100).map(|x| cost_function(&x)).sum();
}

Panics

This function panics if steps < 2 as this would violate the property that the iterator visits both endpoints.