aoko/standard/functions/
ext.rs1use crate::no_std::functions::ext::AnyExt1;
2use std::{prelude::v1::*, fmt::{Debug, Display}, time::{Instant, Duration}};
3
4pub trait StdAnyExt1<R>: Sized {
7 fn measure_time(self, f: impl FnOnce(Self) -> R) -> Duration {
9 Instant::now().also_ref(|_| f(self)).elapsed()
10 }
11
12 fn measure_time_with_value(self, f: impl FnOnce(Self) -> R) -> (R, Duration) {
15 Instant::now().let_owned(|s| (f(self), s.elapsed()))
16 }
17
18 fn measure_time_with_self(self, f: impl FnOnce(&Self) -> R) -> (Self, Duration) {
21 Instant::now().also_ref(|_| f(&self)).let_owned(|s| (self, s.elapsed()))
22 }
23
24 fn measure_time_with_mut_self(mut self, f: impl FnOnce(&mut Self) -> R) -> (Self, Duration) {
27 Instant::now().also_ref(|_| f(&mut self)).let_owned(|s| (self, s.elapsed()))
28 }
29}
30
31impl<T, R> StdAnyExt1<R> for T {}
32
33pub trait StdAnyExt: Sized {
35 fn dbg(self) -> Self where Self: Debug {
39 self.also_ref(|s| println!("{:#?}", s))
40 }
41
42 fn sout(self) -> Self where Self: Debug {
46 self.also_ref(|s| println!("{:?}", s))
47 }
48
49 fn echo(self) -> Self where Self: Display {
51 self.also_ref(|s| println!("{}", s))
52 }
53}
54
55impl<T> StdAnyExt for T {}