use crate::no_std::functions::ext::AnyExt1;
use std::{prelude::v1::*, fmt::{Debug, Display}, time::{Instant, Duration}};
pub trait StdAnyExt1<R>: Sized {
fn measure_time(self, f: impl FnOnce(Self) -> R) -> Duration {
Instant::now().also_ref(|_| f(self)).elapsed()
}
fn measure_time_with_value(self, f: impl FnOnce(Self) -> R) -> (R, Duration) {
Instant::now().let_owned(|s| (f(self), s.elapsed()))
}
fn measure_time_with_self(self, f: impl FnOnce(&Self) -> R) -> (Self, Duration) {
Instant::now().also_ref(|_| f(&self)).let_owned(|s| (self, s.elapsed()))
}
fn measure_time_with_mut_self(mut self, f: impl FnOnce(&mut Self) -> R) -> (Self, Duration) {
Instant::now().also_ref(|_| f(&mut self)).let_owned(|s| (self, s.elapsed()))
}
}
impl<T, R> StdAnyExt1<R> for T {}
pub trait StdAnyExt: Sized {
fn dbg(self) -> Self where Self: Debug {
self.also_ref(|s| println!("{:#?}", s))
}
fn sout(self) -> Self where Self: Debug {
self.also_ref(|s| println!("{:?}", s))
}
fn echo(self) -> Self where Self: Display {
self.also_ref(|s| println!("{}", s))
}
}
impl<T> StdAnyExt for T {}