run/lib.rs
1//! crate that only bendn will ever use
2use std::ops::Range;
3
4mod seal {
5 pub trait Seal {}
6}
7use seal::Seal;
8
9/// Run a function N times
10pub trait Run<D = ()>: Seal {
11 /// Run it a certain number of times.
12 /// ```
13 /// # use crate::run::Run;
14 /// // twice.
15 /// (|| dbg!("ya")).run(2);
16 /// ```
17 fn run<T: Default>(self, n: T)
18 where
19 Range<T>: Iterator;
20}
21
22impl<D, F: FnMut() -> D> Seal for F {}
23impl<D, F: FnMut() -> D + Seal> Run<D> for F {
24 fn run<T: Default>(mut self, n: T)
25 where
26 Range<T>: Iterator,
27 {
28 (T::default()..n).for_each(|_| drop(self()));
29 }
30}