1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
///all Traits
#[allow(warnings)]
pub mod traits {
    use std::thread::JoinHandle;
    use std::{
        any::Any,
        fmt::{Debug, Display},
        path::{Path, PathBuf},
        ptr::null,
        str::FromStr,
    };

    pub trait Spawn<T: Debug> {
        /// ## spawn
        /// ```ignore
        /// use doe::*;
        /// use doe::keyboard::exit_if_click_esc;
        /// let t1 = run.spawn();
        /// let t2 = exit_if_click_esc.spawn();
        /// t1.join();
        /// t2.join();
        /// ```
        ///
        fn spawn(self) -> JoinHandle<T>;
    }
    impl<T: 'static + Send + Debug, F: FnOnce() -> T + Send + 'static> Spawn<T> for F {
        fn spawn(self) -> JoinHandle<T> {
            std::thread::spawn(self)
        }
    }
    pub trait Decimal {
        fn round_to(&self, by: usize) -> Self
        where
            Self: Sized + Copy,
        {
            *self
        }
        fn random() -> Self;
        ///```ignore
        ///  use doe::*;
        ///  f32::random_in_range(0.0..10.0).dprintln();
        ///  i128::random_in_range(10..99).dprintln();
        /// ```
        fn random_in_range<R: std::ops::RangeBounds<Self>>(range: R) -> Self;
        ///num_to_xl_col
        /// ```ignore
        /// use doe::*;
        /// 0.num_to_xl_col().dprintln();
        /// "A".xl_col_to_num().dprintln();
        /// ```
        /// 
        fn num_to_xl_col(&self) -> String;
    }
    impl Decimal for i32 {
        fn num_to_xl_col(&self) -> String{
            let index = *self as usize + 1;
            let mut result = String::new();
            let mut index = index;
        
            while index > 0 {
                let remainder = (index - 1) % 26;
                result.push((b'A' + remainder as u8) as char);
                index = (index - 1) / 26;
            }
        
            result.chars().rev().collect()
        }
        fn random() -> Self {
            (LCG::new().random() * 10.0) as i32
        }

        fn random_in_range<R: std::ops::RangeBounds<Self>>(range: R) -> Self {
            let min = match range.start_bound() {
                std::ops::Bound::Included(v) => *v,
                std::ops::Bound::Excluded(v) => *v,
                std::ops::Bound::Unbounded => 0,
            };

            let max = match range.end_bound() {
                std::ops::Bound::Included(v) => *v,
                std::ops::Bound::Excluded(v) => *v,
                std::ops::Bound::Unbounded => i32::MAX,
            };

            let random = LCG::new().random();
            let sub = max - min;
            (random * sub as f64) as i32 + min
        }
    }
    impl Decimal for i64 {
        fn num_to_xl_col(&self) -> String{
            let index = *self as usize + 1;
            let mut result = String::new();
            let mut index = index;
        
            while index > 0 {
                let remainder = (index - 1) % 26;
                result.push((b'A' + remainder as u8) as char);
                index = (index - 1) / 26;
            }
        
            result.chars().rev().collect()
        }
        fn random() -> Self {
            (LCG::new().random() * 10.0) as i64
        }

        fn random_in_range<R: std::ops::RangeBounds<Self>>(range: R) -> Self {
            let min = match range.start_bound() {
                std::ops::Bound::Included(v) => *v,
                std::ops::Bound::Excluded(v) => *v,
                std::ops::Bound::Unbounded => 0,
            };

            let max = match range.end_bound() {
                std::ops::Bound::Included(v) => *v,
                std::ops::Bound::Excluded(v) => *v,
                std::ops::Bound::Unbounded => i64::MAX,
            };

            let random = LCG::new().random();
            let sub = max - min;
            (random * sub as f64) as i64 + min
        }
    }
    impl Decimal for i128 {
        fn num_to_xl_col(&self) -> String{
            let index = *self as usize + 1;
            let mut result = String::new();
            let mut index = index;
        
            while index > 0 {
                let remainder = (index - 1) % 26;
                result.push((b'A' + remainder as u8) as char);
                index = (index - 1) / 26;
            }
        
            result.chars().rev().collect()
        }
        fn random() -> Self {
            (LCG::new().random() * 10.0) as i128
        }

        fn random_in_range<R: std::ops::RangeBounds<Self>>(range: R) -> Self {
            let min = match range.start_bound() {
                std::ops::Bound::Included(v) => *v,
                std::ops::Bound::Excluded(v) => *v,
                std::ops::Bound::Unbounded => 0,
            };

            let max = match range.end_bound() {
                std::ops::Bound::Included(v) => *v,
                std::ops::Bound::Excluded(v) => *v,
                std::ops::Bound::Unbounded => i128::MAX,
            };

            let random = LCG::new().random();
            let sub = max - min;
            (random * sub as f64) as i128 + min
        }
    }
    impl Decimal for u32 {
        fn num_to_xl_col(&self) -> String{
            let index = *self as usize + 1;
            let mut result = String::new();
            let mut index = index;
        
            while index > 0 {
                let remainder = (index - 1) % 26;
                result.push((b'A' + remainder as u8) as char);
                index = (index - 1) / 26;
            }
        
            result.chars().rev().collect()
        }
        fn random() -> Self {
            (LCG::new().random() * 10.0) as u32
        }

        fn random_in_range<R: std::ops::RangeBounds<Self>>(range: R) -> Self {
            let min = match range.start_bound() {
                std::ops::Bound::Included(v) => *v,
                std::ops::Bound::Excluded(v) => *v,
                std::ops::Bound::Unbounded => 0,
            };

            let max = match range.end_bound() {
                std::ops::Bound::Included(v) => *v,
                std::ops::Bound::Excluded(v) => *v,
                std::ops::Bound::Unbounded => u32::MAX,
            };

            let random = LCG::new().random();
            let sub = max - min;
            (random * sub as f64) as u32 + min
        }
    }
    impl Decimal for u64 {
        fn num_to_xl_col(&self) -> String{
            let index = *self as usize + 1;
            let mut result = String::new();
            let mut index = index;
        
            while index > 0 {
                let remainder = (index - 1) % 26;
                result.push((b'A' + remainder as u8) as char);
                index = (index - 1) / 26;
            }
        
            result.chars().rev().collect()
        }
        fn random() -> Self {
            (LCG::new().random() * 10.0) as u64
        }

        fn random_in_range<R: std::ops::RangeBounds<Self>>(range: R) -> Self {
            let min = match range.start_bound() {
                std::ops::Bound::Included(v) => *v,
                std::ops::Bound::Excluded(v) => *v,
                std::ops::Bound::Unbounded => 0,
            };

            let max = match range.end_bound() {
                std::ops::Bound::Included(v) => *v,
                std::ops::Bound::Excluded(v) => *v,
                std::ops::Bound::Unbounded => u64::MAX,
            };

            let random = LCG::new().random();
            let sub = max - min;
            (random * sub as f64) as u64 + min
        }
    }

    impl Decimal for u128 {
        fn num_to_xl_col(&self) -> String{
            let index = *self as usize + 1;
            let mut result = String::new();
            let mut index = index;
        
            while index > 0 {
                let remainder = (index - 1) % 26;
                result.push((b'A' + remainder as u8) as char);
                index = (index - 1) / 26;
            }
        
            result.chars().rev().collect()
        }
        fn random() -> Self {
            (LCG::new().random() * 10.0) as u128
        }

        fn random_in_range<R: std::ops::RangeBounds<Self>>(range: R) -> Self {
            let min = match range.start_bound() {
                std::ops::Bound::Included(v) => *v,
                std::ops::Bound::Excluded(v) => *v,
                std::ops::Bound::Unbounded => 0,
            };

            let max = match range.end_bound() {
                std::ops::Bound::Included(v) => *v,
                std::ops::Bound::Excluded(v) => *v,
                std::ops::Bound::Unbounded => u128::MAX,
            };

            let random = LCG::new().random();
            let sub = max - min;
            (random * sub as f64) as u128 + min
        }
    }
    impl Decimal for f64 {
        fn num_to_xl_col(&self) -> String{
            let index = *self as usize + 1;
            let mut result = String::new();
            let mut index = index;
        
            while index > 0 {
                let remainder = (index - 1) % 26;
                result.push((b'A' + remainder as u8) as char);
                index = (index - 1) / 26;
            }
        
            result.chars().rev().collect()
        }
        fn round_to(&self, by: usize) -> f64 {
            let factor = 10.0_f64.powi(by as i32);
            (self * factor).round() / factor
        }
        fn random() -> Self {
            LCG::new().random()
        }

        fn random_in_range<R: std::ops::RangeBounds<Self>>(range: R) -> Self {
            let min = match range.start_bound() {
                std::ops::Bound::Included(v) => *v,
                std::ops::Bound::Excluded(v) => *v,
                std::ops::Bound::Unbounded => 0.0,
            };

            let max = match range.end_bound() {
                std::ops::Bound::Included(v) => *v,
                std::ops::Bound::Excluded(v) => *v,
                std::ops::Bound::Unbounded => f64::MAX,
            };

            let random = LCG::new().random();
            let sub = max - min;
            (random * sub) + min
        }
    }

    impl Decimal for f32 {
        fn num_to_xl_col(&self) -> String{
            let index = *self as usize + 1;
            let mut result = String::new();
            let mut index = index;
        
            while index > 0 {
                let remainder = (index - 1) % 26;
                result.push((b'A' + remainder as u8) as char);
                index = (index - 1) / 26;
            }
        
            result.chars().rev().collect()
        }
        
        fn round_to(&self, by: usize) -> f32 {
            let factor = 10.0_f32.powi(by as i32);
            (self * factor).round() / factor
        }
        fn random() -> Self {
            LCG::new().random_f32()
        }
        fn random_in_range<R: std::ops::RangeBounds<Self>>(range: R) -> Self {
            let min = match range.start_bound() {
                std::ops::Bound::Included(v) => *v,
                std::ops::Bound::Excluded(v) => *v,
                std::ops::Bound::Unbounded => 0.0,
            };

            let max = match range.end_bound() {
                std::ops::Bound::Included(v) => *v,
                std::ops::Bound::Excluded(v) => *v,
                std::ops::Bound::Unbounded => f32::MAX,
            };

            let random = LCG::new().random_f32();
            let sub = max - min;
            (random * sub) + min
        }
    }

    pub trait DynType: ToString {}
    impl<T: ToString> DynType for T {}
    /// this is a ToStringWrapper Struct for implementing Into to Box<dyn DynType>
    #[derive(Debug, Clone)]
    pub struct ToDynType<T: ToString>(pub T);
    impl<T: ToString> Into<Box<dyn DynType>> for ToDynType<T> {
        fn into(self) -> Box<dyn DynType> {
            Box::new(self.0.to_string())
        }
    }
    use std::ops::Deref;

    use crate::LCG;
    pub trait Join {
        fn join(&self, by: &str) -> String;
    }

    impl<T: ToString> Join for [T] {
        fn join(&self, by: &str) -> String {
            self.iter()
                .map(|item| item.to_string())
                .collect::<Vec<String>>()
                .join(by)
        }
    }

    pub trait Vector<T> {
        fn element_to_string(&self) -> Vec<String>;
        fn to_string_lossy(&self) -> String;
        fn split_by_slice(&self, slice: &[T]) -> Vec<Vec<T>>;
        fn random_choose(&self) -> T;
    }
    impl<T: ToString + PartialEq + Clone> Vector<T> for [T] {
        fn element_to_string(&self) -> Vec<String> {
            self.iter().map(|x| x.to_string()).collect::<Vec<String>>()
        }

        fn to_string_lossy(&self) -> String {
            let vec = self
                .iter()
                .map(|x| x.to_string().parse::<u8>().unwrap())
                .collect::<Vec<u8>>();
            String::from_utf8_lossy(&vec).to_string()
        }

        fn split_by_slice(&self, slice: &[T]) -> Vec<Vec<T>> {
            let mut result = Vec::new();
            let mut start = 0;

            while let Some(index) = self[start..]
                .windows(slice.len())
                .position(|window| window == slice)
            {
                let end = start + index;
                result.push(self[start..end].to_vec());
                start = end + slice.len();
            }

            result.push(self[start..].to_vec());

            result
        }

        ///random_choose
        ///```rust
        ///use doe::*;  
        ///let v = vec![1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
        ///v.random_choose().dprintln();
        /// ```
        ///
        fn random_choose(&self) -> T {
            use crate::LCG;
            let lcg = LCG::new();
            let random_index = lcg.random_in_range(0..self.len() as i128);
            self.clone().get(random_index as usize).unwrap().to_owned()
        }
    }
    pub trait Str {
        fn cut(&self, start: i32, end: i32, step: usize) -> String;

        fn format(&self, targets: Vec<(Box<dyn ToString>, Box<dyn ToString>)>) -> String;
        /// str String to Path
        fn to_path(&self) -> Box<Path>;
        /// str String to PathBuf
        fn to_path_buf(&self) -> PathBuf;
        ///split string by delimiter into Vec<String>
        fn split_to_vec(&self, delimiter: &str) -> Vec<String>;
        ///string into Box<str>
        fn to_box(&self) -> Box<str>;
        ///push back item to string
        fn push_back(&self, item: impl ToString) -> String;
        ///push front item to string
        fn push_front(&self, item: impl ToString) -> String;
        ///is equal return true
        fn is_equal(&self, other: &Self) -> bool;
        //add two string
        fn add(&self, other: &Self) -> String;
        //reverse string
        fn reverse(&self) -> String;
        //capitalize string
        fn capitalize(&self) -> String;
        /// trim start of string
        fn trim_lines(&self) -> String;
        /// convert xl col to num
        /// ```ignore
        /// use doe::*;
        /// 0.num_to_xl_col().dprintln();
        /// "A".xl_col_to_num().dprintln();
        /// ```
        /// 
        fn xl_col_to_num(&self) -> usize;
        /// convert 'A1' to (col, row) = (0,1)
        fn coordinate_to_position(&self) -> (usize, usize);
    }

    impl<S: ToString> Str for S {
        fn coordinate_to_position(&self) -> (usize, usize){
            let coord_str = self.to_string();
            let mut col_str = String::new();
            let mut row_str = String::new();
            for c in coord_str.chars() {
                if c.is_digit(10) {
                    row_str.push(c);
                } else {
                    col_str.push(c);
                }
            }
            let col_num = col_str.xl_col_to_num();
            let row_num = row_str.parse::<usize>().unwrap();
            (col_num, row_num)
        }
        fn xl_col_to_num(&self) -> usize{
            let col_str = self.to_string().to_uppercase();
            let mut col_num = 0;
            for (i, c) in col_str.chars().enumerate() {
                if (c as u8 as i8 - 'A' as u8 as i8) >= 0 {
                    let offset = (c as u8 - b'A') as usize + 1;
                    col_num = col_num * 26 + offset;
                }
            }
            col_num -1
        }
        //add two string
        fn add(&self, other: &Self) -> String {
            format!("{}{}", self.to_string(), other.to_string())
        }
        ///is equal return true
        fn is_equal(&self, other: &Self) -> bool {
            self.to_string() == other.to_string()
        }
        ///push back item to string
        fn push_back(&self, item: impl ToString) -> String {
            format!("{}{}", self.to_string(), item.to_string())
        }

        ///push front item to string
        fn push_front(&self, item: impl ToString) -> String {
            format!("{}{}", item.to_string(), self.to_string().to_string())
        }
        /// ## implment cut format for str and String
        /// ```rust
        ///fn main() {
        ///    use doe::Str;
        ///    use doe::targets;
        ///    let a = "this is a demo {}";
        ///    let c = a.cut(-1,-2,1);
        ///    let f = a.format(targets!("{}"=>"this is a demo"));
        ///    println!("{:?}",f);
        ///    println!("{:?}",c);
        ///}
        /// ```
        fn cut(&self, start: i32, end: i32, step: usize) -> String {
            let mut res = String::new();
            if start >= 0 && end >= 0 && start <= end {
                let start = start as usize;
                let end = end as usize;
                for (i, c) in self.to_string().chars().enumerate().step_by(step) {
                    if i >= start && i <= end {
                        res.push(c);
                    }
                }
            } else if start < 0 && end < 0 {
                if start > end {
                    let start = self.to_string().len() as i32 + end;
                    let end = self.to_string().len() as i32 + start;
                    let start = start as usize;
                    let end = end as usize;
                    for (i, c) in self.to_string().chars().enumerate().step_by(step) {
                        if i >= start && i <= end {
                            res.push(c);
                        }
                    }
                } else {
                    let start = self.to_string().len() as i32 + start;
                    let end = self.to_string().len() as i32 + end;
                    let start = start as usize;
                    let end = end as usize;
                    for (i, c) in self.to_string().chars().enumerate().step_by(step) {
                        if i >= start && i <= end {
                            res.push(c);
                        }
                    }
                }
            } else if start > 0 && end < 0 {
                let start = start as usize;
                let end = self.to_string().len() as i32 + end;
                let end = end as usize;
                for (i, c) in self.to_string().chars().enumerate().step_by(step) {
                    if i >= start && i <= end {
                        res.push(c);
                    }
                }
            }
            res
        }

        /// ## implment format for str and String
        /// ```rust
        ///fn main() {
        ///    use doe::*;
        ///    "this is a {s},I like Trait Object {p}%"
        ///    .format(vec![(Box::new("{s}"),Box::new("demo")),(Box::new("{p}"),Box::new(100))]).println();//this is a demo,I like Trait Object 100%
        ///     use doe::targets;
        ///     "this is a {d},I like Trait Object {p}}%"
        ///     .format(targets!{"{d}"=>"demo","{p}"=>100})
        ///     .println(); //this is a demo,I like Trait Object 100%
        ///     
        ///     let a = "demo";
        ///     let b_a: Box<str> = a.to_box();
        ///     b_a.as_ref().dprintln();
        ///}
        /// ```
        fn format(&self, targets: Vec<(Box<dyn ToString>, Box<dyn ToString>)>) -> String {
            let mut s_mut = self.to_string().to_string();
            for t in targets {
                s_mut = s_mut.replace(&t.0.deref().to_string(), &t.1.deref().to_string());
            }
            s_mut
        }
        fn to_path(&self) -> Box<Path> {
            Path::new(&self.to_string()).to_owned().into()
        }
        fn to_path_buf(&self) -> PathBuf {
            PathBuf::from_str(&self.to_string()).unwrap()
        }
        fn split_to_vec(&self, delimiter: &str) -> Vec<String> {
            crate::split_to_vec!(self.to_string(), delimiter)
        }
        fn to_box(&self) -> Box<str> {
            Box::from(self.to_string())
        }
        ///reverse string
        /// ```rust
        /// use doe::Str;
        /// use doe::*;
        /// "a string".reverse().println(); //"gnirts a"
        /// ```
        ///
        fn reverse(&self) -> String {
            let mut s = self.to_string().chars().rev().collect::<Vec<_>>();
            s.join("")
        }
        //capitalize string
        fn capitalize(&self) -> String {
            if let Some(c) = self.to_string().chars().next() {
                let first_letter_capitalized = c.to_uppercase().collect::<String>();
                let rest_of_string = &self.to_string()[1..];
                return format!("{}{}", first_letter_capitalized, rest_of_string);
            }
            self.to_string()
        }

        fn trim_lines(&self) -> String {
            self.split_to_vec("\n")
                .iter()
                .map(|s| s.trim().to_string())
                .collect::<Vec<_>>()
                .join("\n")
        }
    }
    pub trait Then {
        fn then(&self, run: impl Fn()) -> &Self;
    }

    impl<T> Then for T {
        fn then(&self, run: impl Fn()) -> &Self {
            run();
            self
        }
    }
    pub trait Sleep {
        fn sleep(&self, secs: f64);
    }
    impl<T> Sleep for T {
        fn sleep(&self, secs: f64) {
            use std::thread::sleep;
            use std::time::Duration;
            sleep(Duration::from_secs_f64(secs));
        }
    }

    /// A trait for impl Debug
    pub trait DebugPrint {
        /// debug print
        /// ```rust
        /// use doe::DebugPrint;
        /// let get = |url:&str|url.to_string().dprint();
        /// ```
        fn dprint(&self);
        /// debug eprint
        /// ```rust
        /// use doe::DebugPrint;
        /// let get = |url:&str|url.to_string().deprint();
        /// ```
        fn deprint(&self);
        /// debug println
        /// ```rust
        /// use doe::DebugPrint;
        /// let get = |url:&str|url.to_string().dprintln();
        /// ```
        fn dprintln(&self);
        /// debug eprintln
        /// ```rust
        /// use doe::DebugPrint;
        /// let get = |url:&str|url.to_string().deprintln();
        /// ```
        fn deprintln(&self);
        /// ```rust
        /// fn main() {
        ///     use doe::DebugPrint;
        ///     #[derive(Debug)]
        ///     struct Demo{}
        ///     let d = Demo{};
        ///     d.dbg();
        /// }
        /// ```
        fn dbg(&self);
    }
    impl<T> DebugPrint for T
    where
        T: Debug,
    {
        fn dprint(&self) {
            print!("{:?}", self);
        }
        fn deprint(&self) {
            eprint!("{:?}", self);
        }

        fn dprintln(&self) {
            println!("{:?}", self);
        }
        fn deprintln(&self) {
            eprintln!("{:?}", self);
        }
        fn dbg(&self) {
            dbg!(self);
        }
    }
    pub trait Print {
        /// ```rust
        /// use doe::Print;
        /// let get = |url:&str|url.to_string().print();
        /// ```
        fn print(&self);
        /// ```rust
        /// use doe::Print;
        /// let get = |url:&str|url.to_string().print();
        /// ```
        fn eprint(&self);
        /// ```rust
        /// use doe::Print;
        /// let get = |url:&str|url.to_string().println();
        /// ```
        fn println(&self);
        /// ```rust
        /// use doe::Print;
        /// let get = |url:&str|url.to_string().println();
        /// ```
        fn eprintln(&self);
    }
    impl<T> Print for T
    where
        T: Display,
    {
        fn print(&self) {
            print!("{}", self);
        }
        fn eprint(&self) {
            eprint!("{}", self);
        }

        fn println(&self) {
            println!("{}", self);
        }
        fn eprintln(&self) {
            eprintln!("{}", self);
        }
    }
    ///IsThen
    /// ```rust
    ///use doe::*;
    ///let a = Some(1);
    ///let b: Result<i32, Box<dyn std::error::Error>> = Err("error".into());
    ///b.is_ok_then(|s| {
    ///}).is_none_then(|| {
    ///    println!("NONE");
    ///});
    /// ```
    pub trait IsThen<T> {
        fn is_some_then(self, f: impl FnOnce(T) -> T) -> Option<T>;
        fn is_none_then(self, f: impl FnOnce());
        fn is_ok_then(self, f: impl FnOnce(T)) -> Option<T>;
        fn is_err_then(self, f: impl FnOnce());
    }

    impl<T: Clone, U> IsThen<T> for Result<T, U> {
        fn is_some_then(self, f: impl FnOnce(T) -> T) -> Option<T> {
            match self {
                Ok(value) => Some(f(value)),
                Err(_) => None,
            }
        }

        fn is_none_then(self, f: impl FnOnce()) {
            if self.is_err() {
                f();
            }
        }

        fn is_ok_then(self, f: impl FnOnce(T)) -> Option<T> {
            match self {
                Ok(value) => {
                    f(value.clone());
                    Some(value)
                }
                Err(_) => None,
            }
        }

        fn is_err_then(self, f: impl FnOnce()) {
            if self.is_err() {
                f();
            }
        }
    }

    impl<T: Clone> IsThen<T> for Option<T> {
        fn is_some_then(self, f: impl FnOnce(T) -> T) -> Option<T> {
            match self {
                Some(value) => Some(f(value)),
                None => None,
            }
        }

        fn is_none_then(self, f: impl FnOnce()) {
            if self.is_none() {
                f();
            }
        }

        fn is_ok_then(self, f: impl FnOnce(T)) -> Option<T> {
            match self {
                Some(value) => {
                    f(value.clone());
                    Some(value)
                }
                None => None,
            }
        }

        fn is_err_then(self, f: impl FnOnce()) {
            if self.is_none() {
                f();
            }
        }
    }
}