easy_paths 0.1.1

Convenience library for rapidly processing string-type paths.
Documentation
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
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
//
// Libraries - native
//
use std::ffi::OsStr;
use std::fmt::{Debug, Display};
use std::fs::DirEntry;
use std::path::{Path, PathBuf};
//
// Libraries - downloaded
//
use shellexpand;
use substring::Substring;
//
// Tests
//
#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn test_get_absolute_path() {
        let string_path = "./test/test_b/test_c/../";
        assert_eq!(
            get_absolute_path(&string_path),
            format!("{}/test/test_b", env!("CARGO_MANIFEST_DIR")),
        );
        let string_result = get_absolute_path(&"~/test");
        if string_result.contains("~") {
            panic!("Result contains tilde.")
        }
        if !string_result.ends_with("/test") {
            panic!("Result doesn't end with '/test'.")
        }
    }

    #[test]
    fn test_get_absolute_path_or_error() {
        let string_path = "./test/test_b/test_c/../";
        let result = match get_absolute_path_or_error(&string_path) {
            Ok(string_result) => string_result,
            Err(err) => panic!("{}", err,),
        };
        let expected = format!("{}/test/test_b", env!("CARGO_MANIFEST_DIR").to_string(),);
        assert_eq!(result, expected)
    }

    #[test]
    fn test_get_base_name_with_extension() {
        let string_path = "test/test_a/text_a_a.txt";
        let result = match get_base_name(&string_path) {
            Some(string_result) => string_result,
            None => panic!(""),
        };
        let expected = "text_a_a.txt".to_string();
        assert_eq!(result, expected)
    }

    #[test]
    fn test_get_base_name_on_dir() {
        let string_path = "test/test_b/test_c/text_b_c_a.txt";
        let result = match get_base_name(&string_path) {
            Some(string_result) => string_result,
            None => panic!(""),
        };
        let expected = "text_b_c_a.txt".to_string();
        assert_eq!(result, expected)
    }

    #[test]
    fn test_get_common_path() {
        let slice_of_strings = [
            "src/helpers_disk/A/B/C",
            "src/helpers_disk/A/B",
            "src/helpers_disk/A",
        ];
        let result = match get_common_path(&slice_of_strings) {
            Ok(string_result) => string_result,
            Err(err) => panic!("{}", err),
        };
        let expected = "src".to_string();
        assert_eq!(result, expected)
    }

    #[test]
    fn test_get_common_prefix() {
        let slice_of_strings = [
            "src/helpers_disk/A/B/C",
            "src/helpers_disk/A/B",
            "src/helpers_disk/A",
        ];
        let result = match get_common_prefix(&slice_of_strings) {
            Ok(string_result) => string_result,
            Err(err) => panic!("{}", err),
        };
        let expected = "src/helpers_disk/A".to_string();
        assert_eq!(result, expected)
    }

    #[test]
    fn test_get_dir_name() {
        let string_path = "test/test_b/test_c/text_b_c_a.txt";
        let result = match get_dir_name(&string_path) {
            Some(string_result) => string_result,
            None => panic!("Failed"),
        };
        let expected = "test/test_b/test_c".to_string();
        assert_eq!(result, expected)
    }

    #[test]
    fn test_get_dir_ancestor_n_levels_up() {
        let string_path = "test/test_b/test_c/text_b_c_a.txt";
        let int_layers_up: usize = 2;
        let result = match get_dir_ancestor_n_levels_up(&string_path, int_layers_up) {
            Some(string_result) => string_result,
            None => panic!("Failed"),
        };
        let expected = "test/test_b".to_string();
        assert_eq!(result, expected)
    }

    #[test]
    fn test_get_dir_ancestor_that_exists() {
        let string_path = "test/test_b/test_c/text_b_c_a.txt/A/B/C";
        let result = match get_dir_ancestor_that_exists(&string_path) {
            Some(string_result) => string_result,
            None => panic!("Failed"),
        };
        let expected = "test/test_b/test_c/text_b_c_a.txt".to_string();
        assert_eq!(result, expected)
    }

    #[test]
    fn test_get_extension() {
        let string_path = "test/test_b/test_c/text_b_c_a.txt";
        let result = match get_extension(&string_path) {
            Some(string_result) => string_result,
            None => panic!("Failed"),
        };
        let expected = "txt".to_string();
        assert_eq!(result, expected)
    }

    #[test]
    fn test_get_only_dirs_from_slice() {
        let slice_of_strings = [
            "test/test_b",
            "test/test_b/test_c",
            "test/test_b/test_c/text_b_c_b.txt",
            "test/test_b/test_c/text_b_c_a.txt",
            "test/test_a",
            "test/test_a/text_a_a.txt",
        ];
        let result = get_only_dirs_from_slice(&slice_of_strings);
        let expected = ["test/test_b", "test/test_b/test_c", "test/test_a"]
            .iter()
            .map(|item| format!("{}", item,))
            .collect::<Vec<String>>();
        assert_eq!(result, expected,)
    }

    #[test]
    fn test_get_only_file_paths_from_slice() {
        let slice_of_strings = [
            "test/test_b",
            "test/test_b/test_c",
            "test/test_b/test_c/text_b_c_b.txt",
            "test/test_b/test_c/text_b_c_a.txt",
            "test/test_a",
            "test/test_a/text_a_a.txt",
        ];
        let result = get_only_file_paths_from_slice(&slice_of_strings);
        let expected = [
            "test/test_b/test_c/text_b_c_b.txt",
            "test/test_b/test_c/text_b_c_a.txt",
            "test/test_a/text_a_a.txt",
        ]
        .iter()
        .map(|item| format!("{}", item,))
        .collect::<Vec<String>>();
        assert_eq!(result, expected,)
    }

    #[test]
    fn test_get_path_joined() {
        let slice_of_strings = ["A", "B", "C"];
        let result = match get_path_joined(&slice_of_strings) {
            Some(string_result) => string_result,
            None => panic!("Failed"),
        };
        let expected = "A/B/C".to_string();
        assert_eq!(result, expected)
    }

    #[test]
    fn test_get_paths_in_dir() {
        let string_path = "test";
        let result = match get_paths_in_dir(&string_path) {
            Ok(vec_result) => vec_result,
            Err(err) => panic!("{}", err,),
        };
        let expected = ["test/test_a", "test/test_b"]
            .iter()
            .map(|item_str| item_str.to_string())
            .collect::<Vec<String>>();
        assert_eq!(result, expected)
    }

    #[test]
    fn test_get_paths_in_dir_and_sub_dirs() {
        let string_path = "test";
        let result = match get_paths_in_dir_and_sub_dirs(&string_path) {
            Ok(vec_result) => vec_result,
            Err(err) => panic!("{}", err),
        };
        let expected = [
            "test/test_b",
            "test/test_b/test_c",
            "test/test_b/test_c/text_b_c_b.txt",
            "test/test_b/test_c/text_b_c_a.txt",
            "test/test_a",
            "test/test_a/text_a_a.txt",
        ]
        .iter()
        .map(|item_str| item_str.to_string())
        .collect::<Vec<String>>();
        assert_eq!(result, expected)
    }

    #[test]
    fn test_get_paths_sorted_by_size_starting_with_shortest() {
        let slice_of_strings = ["/A/B/C", "/A", "/A/B"];
        let result = match get_paths_sorted_by_size_starting_with_shortest(&slice_of_strings) {
            Ok(vec_result) => vec_result,
            Err(err) => panic!("{}", err),
        };
        let expected = ["/A", "/A/B", "/A/B/C"]
            .iter()
            .map(|item_str| item_str.to_string())
            .collect::<Vec<String>>();
        assert_eq!(result, expected)
    }

    #[test]
    fn test_get_paths_to_only_dirs_in_dir_and_sub_dirs() {
        let string_path = "test";
        let result = match get_paths_to_only_dirs_in_dir_and_sub_dirs(&string_path) {
            Ok(vec_result) => vec_result,
            Err(err) => panic!("{}", err,),
        };
        let expected = ["test/test_b", "test/test_b/test_c", "test/test_a"]
            .iter()
            .map(|item_str| item_str.to_string())
            .collect::<Vec<String>>();
        assert_eq!(result, expected)
    }

    #[test]
    fn test_get_paths_to_only_files_in_dir_and_sub_dirs() {
        let string_path = "test";
        let result = match get_paths_to_only_files_in_dir_and_sub_dirs(&string_path) {
            Ok(vec_result) => vec_result,
            Err(err) => panic!("{}", err,),
        };
        let expected = [
            "test/test_b/test_c/text_b_c_b.txt",
            "test/test_b/test_c/text_b_c_a.txt",
            "test/test_a/text_a_a.txt",
        ]
        .iter()
        .map(|item_str| item_str.to_string())
        .collect::<Vec<String>>();
        assert_eq!(result, expected)
    }

    #[test]
    fn test_get_relative_path() {
        let string_path_abs_root = "/A/B/C";
        let string_path_abs = "/A/B/C/D";
        let result = match get_relative_path(&string_path_abs, &string_path_abs_root) {
            Ok(string_result) => string_result,
            Err(err) => panic!("{}", err,),
        };
        let expected = "D".to_string();
        assert_eq!(result, expected)
    }

    #[test]
    fn test_get_vec_by_splitting_path() {
        let string_path = "test/test_b/test_c/text_b_c_a.txt";
        let result = match get_vec_by_splitting_path(&string_path) {
            Some(vec_result) => vec_result,
            None => panic!("Failed"),
        };
        let expected = ["test", "test_b", "test_c", "text_b_c_a.txt"]
            .iter()
            .map(|item_str| item_str.to_string())
            .collect::<Vec<String>>();
        assert_eq!(result, expected)
    }

    #[test]
    fn test_is_absolute() {
        assert_eq!(is_absolute(&"/A/B/C"), true,)
    }

    #[test]
    fn test_is_existing_path() {
        assert_eq!(is_existing_path(&"test/test_b/test_c/text_b_c_a.txt"), true,)
    }

    #[test]
    fn test_is_path_type() {
        assert_eq!(
            is_path_type(&Path::new(&"test/test_b/test_c/text_b_c_a.txt")),
            true,
        )
    }

    #[test]
    fn test_is_path_buf_type() {
        assert_eq!(
            is_path_buf_type(&PathBuf::from("test/test_b/test_c/text_b_c_a.txt")),
            true,
        )
    }

    #[test]
    fn test_is_path_inside_dir_parent() {
        assert_eq!(
            is_path_inside_dir_parent(&"test/test_b/test_c/text_b_c_a.txt", &"test/test_b"),
            true,
        )
    }

    #[test]
    fn test_raise_error_if_path_is_not_in_project_absolute() {
        let mut string_path = "/badpath";
        match raise_error_if_path_is_not_in_project(&string_path) {
            Ok( () ) => {
                panic!(
                    "{}",
                    [
                        "Did not return error on bad absolute path.".to_string(),
                        format!("string_path = {}", string_path,)
                    ]
                        .join("\n")
                )
            }
            Err( _err ) => {}
        }
        string_path = "test";
        match raise_error_if_path_is_not_in_project(&string_path) {
            Ok(()) => {}
            Err(_err) => {
                panic!(
                    "{}",
                    [
                        "Returned error on good relative path.".to_string(),
                        format!("string_path = {}", string_path,),
                    ]
                        .join("\n")
                )
            }
        }
        string_path = "bad/test";
        match raise_error_if_path_is_not_in_project(&string_path) {
            Ok(()) => {
                panic!(
                    "{}",
                    [
                        "Did not return error on bad relative path.".to_string(),
                        format!("string_path = {}", string_path,),
                    ]
                        .join("\n")
                )
            }
            Err(_err) => {}
        }
    }

    #[test]
    fn test_raise_error_if_path_points_to_src() {
        match raise_error_if_path_points_to_src(&"src") {
            Ok(()) => { panic!("Did not return error") }
            Err( _err ) => {},
        }
        match raise_error_if_path_points_to_src(&"src/") {
            Ok(()) => { panic!("Did not return error") }
            Err(_err) => {},
        }
        match raise_error_if_path_points_to_src(&format!("{}/src/", env!("CARGO_MANIFEST_DIR"),)) {
            Ok(()) => {panic!("No error returned")}
            Err(_err) => {},
        }
        match raise_error_if_path_points_to_src(&"src/") {
            Ok(()) => {panic!("No error returned")}
            Err(_err) => {},
        }
    }

    #[test]
    fn test_raise_error_if_path_points_to_cargo_toml() {
        let mut string_path = format!("{}/Cargo.toml", env!("CARGO_MANIFEST_DIR"),);
        match raise_error_if_path_points_to_cargo_toml(&string_path) {
            Ok(()) => {
                panic!(
                    "{}",
                    [
                        "Didn't raise error when passed the absolute path to Cargo.toml"
                            .to_string(),
                        format!("string_path = {}", string_path,),
                    ]
                        .join("\n")
                )
            }
            Err(_err) => {}
        }
        string_path = "Cargo.toml".to_string();
        match raise_error_if_path_points_to_cargo_toml(&string_path) {
            Ok(()) => {
                panic!(
                    "{}",
                    [
                        "Didn't raise error when passed the relative path to Cargo.toml".to_string(),
                        format!("string_path = {}", string_path,),
                    ]
                        .join("\n")
                )
            }
            Err(_err) => {},
        }
        string_path = "src".to_string();
        match raise_error_if_path_points_to_cargo_toml(&string_path) {
            Ok(()) => {}
            Err(_err) => {
                panic!(
                    "{}",
                    [
                        "Raised error when not pointing to Cargo.toml".to_string(),
                        format!("string_path = {}", string_path,),
                    ]
                        .join("\n")
                )
            }
        }
    }

    #[test]
    fn test_raise_error_if_path_points_to_main_rs() {
        let mut string_path = format!("{}/src/main.rs", env!("CARGO_MANIFEST_DIR"),);
        match raise_error_if_path_points_to_main_rs(&string_path) {
            Ok(()) => {
                panic!(
                    "{}",
                    [
                        "Failed to return error when passed absolute path to main.rs".to_string(),
                        format!("string_path = {}", string_path,),
                    ]
                        .join("\n")
                )
            }
            Err(_err) => {}
        }
        string_path = "src/main.rs".to_string();
        match raise_error_if_path_points_to_main_rs(&string_path) {
            Ok(()) => {
                panic!(
                    "{}",
                    [
                        "Failed to return error when passed relative path to main.rs".to_string(),
                        format!("string_path = {}", string_path,),
                    ]
                        .join("\n")
                )
            }
            Err(_err) => {}
        }
        string_path = "src".to_string();
        match raise_error_if_path_points_to_main_rs(&string_path) {
            Ok(()) => {

            }
            Err(_err) => {
                panic!(
                    "{}",
                    [
                        "Raised error when not pointing at main.rs".to_string(),
                        format!("string_path = {}", string_path,),
                    ]
                        .join("\n")
                )
            }
        }
    }
}
//
// Public - get - paths
//
/// This attempts to get the full path
///
/// If the conversion fails, this will return the 'most complete' string it built
/// up to that point.
///
/// Since canonicalize requires the paths to exist, if the argument doesn't exist in this case
/// this function will return the path with the expanded tilde, but will still contain any positional
/// elements (ie '..')
///
/// This supports '~', '.', '..'
/// # Arguments
/// * arg_string_path: string-like
/// # Examples
/// let string_absolute_path = get_absolute_path( &string_path_relative );
pub fn get_absolute_path<T: Debug + Display>(arg_string_path: &T) -> String {
    let string_path = get_path_with_tilde_expanded_if_necessary(&arg_string_path);
    //
    // Reminder: canonicalize() will throw an error if the path doesn't exist
    //
    match std::fs::canonicalize(PathBuf::from(&string_path)) {
        Ok(path_buf_result) => match path_buf_result.to_str() {
            Some(str_result) => str_result.to_string(),
            None => return string_path,
        },
        Err(_err) => string_path,
    }
}

/// Similar to get_absolute_path() except this is 'all-or-nothing.' If any step fails, this returns
/// an error message explaining which step failed.
/// Since canonicalize requires the final path to exist, this will count as a 'failure' condition.
/// This supports '~', '.', '..'
/// # Arguments
/// * arg_string_path: string-like
/// # Examples
/// let string_absolute_path = match get_absolute_path( &string_path_relative ) {
///     Ok( string_result ) => { string_result }
///     Err( err ) => { panic!( "{}", err ) }
/// };
pub fn get_absolute_path_or_error<T: Debug + Display>(
    arg_string_path: &T,
) -> Result<String, String> {
    let string_path = get_path_with_tilde_expanded_if_necessary(&arg_string_path);
    //
    // Reminder: canonicalize() will throw an error if the path doesn't exist
    //
    match std::fs::canonicalize(PathBuf::from(&string_path)) {
        Ok(path_buf_result) => match path_buf_result.to_str() {
            Some(str_result) => Ok(str_result.to_string()),
            None => {
                return Err([
                    "Error: Failed to extract str from PathBuf.".to_string(),
                    format!("arg_string_path = {}", arg_string_path,),
                    format!("path built = {}", string_path,),
                ]
                .join("\n"))
            }
        },
        Err(err) => {
            return Err([
                "Error: Failed to 'canonicalize' string_path.".to_string(),
                format!("arg_string_path = {}", arg_string_path,),
                format!("err = {}", err,),
                format!("path built = {}", string_path,),
            ]
            .join("\n"))
        }
    }
}

/// Returns a string consisting of only the filename
/// Returns None in case of failure
/// # Arguments
/// * arg_string_path: string-like data type representing a relative path
/// # Examples
/// let string_path = "test/test_a/text_a_a.txt";
/// let result = match get_base_name( &string_path ) {
///     Some( string_result ) => { string_result }
///     None => { panic!( "" ) }
/// };
/// let expected = "text_a_a.txt".to_string();
/// assert_eq!( result, expected )
pub fn get_base_name<T: Debug + Display>(arg_string_path: &T) -> Option<String> {
    match Path::new(&format!("{}", arg_string_path,)).file_name() {
        Some(os_str_result) => match os_str_result.to_str() {
            Some(str_result) => Some(str_result.to_string()),
            None => return None,
        },
        None => return None,
    }
}

/// Returns a string path which is shared between all paths in the slice of string-like values
/// If the common path doesn't exist, the function will then iterate upwards through the common path's
/// ancestors until to a path is found, or no further parents exist.
/// Returns None in case of failure (either no match found, nothing about the common string exists)
/// # Arguments
/// * arg_slice_of_strings: slice of string-like paths
/// # Examples
/// let slice_of_strings = [
///     "/A/B",
///     "/A/B/C",
///     "/A/B/C/D",
/// ];
/// let result = match get_common_path( &slice_of_strings ) {
///     Ok( string_result ) => { string_result }
///     Err( err ) => { panic!( "{}", err ) }
/// };
/// // If '/A/B' exists, then that is the common shared path and the function will return this
/// // If '/A' exists, but '/A/B' is actually fictitious, then the function will continue
/// // fetching the 'parent' directory until it finds one that exists. In this scenario, that
/// // directory would be '/A'
pub fn get_common_path<T: Debug + Display>(arg_slice_of_strings: &[T]) -> Result<String, String> {
    let vec_of_path_bufs =
        get_path_bufs_sorted_by_size_starting_with_shortest(&arg_slice_of_strings);
    let mut path_buf_prefix_to_return = match vec_of_path_bufs.get(0) {
        Some(path_buf_result) => path_buf_result.clone(),
        None => {
            return Err([
                "Error: Failed to get value at index 0.".to_string(),
                format!(
                    "arg_slice_of_strings.len() = {}",
                    arg_slice_of_strings.len()
                ),
                format!(
                    "arg_slice_of_strings.len() = {:#?}",
                    arg_slice_of_strings.len()
                ),
            ]
            .join("\n"))
        }
    };
    loop {
        let bool_all_path_bufs_meet_requirement = {
            let mut bool_all_path_bufs_meet_requirement = true;
            for item_path_buf in &vec_of_path_bufs {
                if !item_path_buf.starts_with(&path_buf_prefix_to_return) {
                    bool_all_path_bufs_meet_requirement = false;
                    break;
                }
            }
            bool_all_path_bufs_meet_requirement
        };
        if bool_all_path_bufs_meet_requirement {
            match path_buf_prefix_to_return.to_str() {
                Some(_str_result) => break,
                None => {
                    return Err([
                        "Error: Failed to extract str from PathBuf.".to_string(),
                        format!(
                            "path buf value at failure = {:?}",
                            path_buf_prefix_to_return
                        ),
                        format!("arg_slice_of_strings = {:#?}", arg_slice_of_strings,),
                    ]
                    .join("\n"))
                }
            }
        } else {
            path_buf_prefix_to_return = match path_buf_prefix_to_return.parent() {
                Some(path_result) => PathBuf::from(path_result),
                None => {
                    return Err([
                        "Error: Attempted to access non-existent parent.".to_string(),
                        format!(
                            "path buf value at failure = {:?}",
                            path_buf_prefix_to_return
                        ),
                        format!("arg_slice_of_strings = {:#?}", arg_slice_of_strings,),
                    ]
                    .join("\n"))
                }
            }
        }
    }
    //
    // Keep getting parent dir until it exists
    //
    loop {
        if path_buf_prefix_to_return.exists() {
            break;
        }
        path_buf_prefix_to_return = match path_buf_prefix_to_return.parent() {
            Some(path_result) => PathBuf::from(path_result),
            None => {
                return Err([
                    "Error: Attempted to access non-existent parent.".to_string(),
                    format!(
                        "path buf value at failure = {:?}",
                        path_buf_prefix_to_return
                    ),
                    format!("arg_slice_of_strings = {:#?}", arg_slice_of_strings,),
                ]
                .join("\n"))
            }
        }
    }
    match path_buf_prefix_to_return.to_str() {
        Some(str_result) => Ok(str_result.to_string()),
        None => Err([
            "Error: Failed to extract str from PathBuf.".to_string(),
            format!(
                "path buf value at failure = {:?}",
                path_buf_prefix_to_return
            ),
            format!("arg_slice_of_strings = {:#?}", arg_slice_of_strings,),
        ]
        .join("\n")),
    }
}

/// Returns a string or None which is the same shared path represented within
/// a slice of string-like paths
/// # Arguments
/// * arg_slice_of_strings: slice of string-like paths
/// # Examples
/// let slice_of_strings = [
///     "/A/B",
///     "/A/B/C",
///     "/A/B/C/D",
/// ];
/// let result = match get_common_prefix( &slice_of_strings ) {
///     Ok( string_result ) => { string_result }
///     Err( err ) => { panic!( "{}", err, ) }
/// };
/// // If '/A/B' exists, then that is the common shared path and the function will return this,
/// // regardless of whether or not this path actually exists
pub fn get_common_prefix<T: Debug + Display>(arg_slice_of_strings: &[T]) -> Result<String, String> {
    let vec_of_path_bufs =
        get_path_bufs_sorted_by_size_starting_with_shortest(&arg_slice_of_strings);
    let mut path_buf_to_return = match vec_of_path_bufs.get(0) {
        Some(path_buf_result) => path_buf_result.clone(),
        None => {
            return Err([
                "Error: Failed to get value at index 0.".to_string(),
                format!(
                    "arg_slice_of_strings.len() = {}",
                    arg_slice_of_strings.len()
                ),
                format!(
                    "arg_slice_of_strings.len() = {:#?}",
                    arg_slice_of_strings.len()
                ),
            ]
            .join("\n"))
        }
    };
    loop {
        let bool_all_path_bufs_meet_requirement = {
            let mut bool_all_path_bufs_meet_requirement = true;
            for item_path_buf in &vec_of_path_bufs {
                if !item_path_buf.starts_with(&path_buf_to_return) {
                    bool_all_path_bufs_meet_requirement = false;
                    break;
                }
            }
            bool_all_path_bufs_meet_requirement
        };
        if bool_all_path_bufs_meet_requirement {
            break;
        }
        path_buf_to_return = match path_buf_to_return.parent() {
            Some(path_result) => PathBuf::from(path_result),
            None => {
                return Err([
                    "Error: Attempted to access non-existent parent.".to_string(),
                    format!("path buf value at failure = {:?}", path_buf_to_return),
                    format!("arg_slice_of_strings = {:#?}", arg_slice_of_strings,),
                ]
                .join("\n"))
            }
        }
    }
    match path_buf_to_return.to_str() {
        Some(str_result) => Ok(str_result.to_string()),
        None => {
            return Err([
                "Error: Failed to extract str from PathBuf.".to_string(),
                format!("path buf value at failure = {:?}", path_buf_to_return),
                format!("arg_slice_of_strings = {:#?}", arg_slice_of_strings,),
            ]
            .join("\n"))
        }
    }
}

/// Returns a string or None which is the path n-layers up
/// # Arguments
/// * arg_string_path: string-like path
/// * arg_n: usize-type value representing the number of layers to iterate through
/// # Examples
/// let result = match get_dir_ancestor_n_levels_up( &"/A/B/C", 2 ) {
///     Some( string_result ) => { string_result }
///     None => { panic!( "Failed to get ancestor" ) }
/// };
/// // result = "/A"
pub fn get_dir_ancestor_n_levels_up<T: Debug + Display>(
    arg_string_path: &T,
    arg_n: usize,
) -> Option<String> {
    let mut path_buf = PathBuf::from(format!("{}", arg_string_path,));
    for _ in 0..arg_n {
        path_buf = match path_buf.parent() {
            Some(path_result) => PathBuf::from(path_result),
            None => return None,
        };
    }
    match path_buf.to_str() {
        Some(str_result) => Some(str_result.to_string()),
        None => None,
    }
}

/// Returns a string or None which is the part of the argument path that actually exists
/// # Arguments
/// * arg_string_path: string-like path
/// # Examples
/// let result = match get_dir_ancestor_that_exists( &"/A/B/C" ) {
///     Some( string_result ) => { string_result }
///     None => { panic!( "Failed to get ancestor" ) }
/// };
/// // The returned string will be "/A/B/C" if it exists
/// // The returned string will be "/A/B" if it exists and "/A/B/C" does not
/// // The returned string will be "/A" if all in-between paths do not exist
pub fn get_dir_ancestor_that_exists<T: Debug + Display>(arg_string_path: &T) -> Option<String> {
    let mut path_buf = PathBuf::from(format!("{}", arg_string_path,));
    loop {
        if path_buf.exists() {
            return match path_buf.to_str() {
                Some(str_result) => Some(str_result.to_string()),
                None => None,
            };
        } else {
            path_buf = match path_buf.parent() {
                Some(path_result) => PathBuf::from(path_result),
                None => return None,
            };
        }
    }
}

/// Returns a string or None which is the path to the current working directory
/// # Examples
/// let result = match get_dir_cwd() {
///     Ok( string_result ) => { string_result }
///     Err( err ) => { panic!( "{}", err, ) }
/// };
pub fn get_dir_cwd() -> Result<String, String> {
    match std::env::current_dir() {
        Ok(path_buf_from_env) => match path_buf_from_env.to_str() {
            Some(str_result) => Ok(str_result.to_string()),
            None => {
                return Err([
                    "Error: could not get str from PathBuf.".to_string(),
                    format!("path_buf_from_env = {:?}", path_buf_from_env,),
                ]
                .join("\n"))
            }
        },
        Err(err) => {
            return Err([
                "Error: could not get PathBuf from std::env::current_dir().".to_string(),
                format!("err = {}", err,),
                format!("std::env::current_dir() = {:?}", std::env::current_dir(),),
            ]
            .join("\n"))
        }
    }
}

/// Returns a string or None which is the path to the current working directory
/// # Arguments
/// * arg_string_path: string-like
/// # Examples
/// let result = match get_dir_name( &"/A/B/C" ) {
///     Some( string_result ) => { string_result }
///     None => { panic!( "Failed to get dirname." ) }
/// };
/// // result = "/A/B"
pub fn get_dir_name<T: Debug + Display>(arg_string_path: &T) -> Option<String> {
    match PathBuf::from(format!("{}", arg_string_path,)).parent() {
        Some(path_result) => match path_result.to_str() {
            Some(str_result) => Some(str_result.to_string()),
            None => None,
        },
        None => None,
    }
}

/// Returns a string representing the path to the project root directory
/// # Examples
/// let result = get_dir_proj_root();
pub fn get_dir_proj_root() -> String {
    env!("CARGO_MANIFEST_DIR").to_string()
}

/// Returns a string representing the file extension without the period
/// # Arguments
/// * arg_string_path: string-like
/// # Examples
/// let result = match get_extension( "file.txt" ) {
///     Some( string_result ) => { string_result }
///     None => { panic!( "Failed to get extension." ) }
/// };
/// // result = "txt"
pub fn get_extension<T: Debug + Display>(arg_string_path: &T) -> Option<String> {
    match Path::new(&format!("{}", arg_string_path,)).extension() {
        Some(os_str_result) => match os_str_result.to_str() {
            Some(str_result) => Some(str_result.to_string()),
            None => return None,
        },
        None => return None,
    }
}

/// Returns a string path pointing at the binary file created by the compilation process
/// # Examples
/// let string_path_file_binary = match get_file_path_binary() {
///     Ok( string_result ) => { string_result }
///     Err( err ) => { panic!( "{}", err, ) }
/// };
pub fn get_file_path_binary() -> Result<String, String> {
    match std::env::current_exe() {
        Ok(path_buf_result) => match path_buf_result.to_str() {
            Some(str_result) => Ok(str_result.to_string()),
            None => Err([
                "Error: failed to convert path to binary file from PathBuff to str".to_string(),
                format!("path_buf_from_current_exe = {:?}", path_buf_result,),
            ]
            .join("\n")),
        },
        Err(err) => Err([
            "Error: failed to get path to binary file outputted by compilation process".to_string(),
            format!("err = {}", err,),
        ]
        .join("\n")),
    }
}

/// Returns a vec of only strings referencing directories from a slice argument
/// # Arguments
/// * arg_slice_of_strings: [] of string-likes
/// # Examples
/// let slice_of_strings = [
///     "test/test_b",
///     "test/test_b/test_c",
///     "test/test_b/test_c/text_b_c_b.txt",
///     "test/test_b/test_c/text_b_c_a.txt",
///     "test/test_a",
///     "test/test_a/text_a_a.txt",
/// ];
/// let result = get_only_dirs_from_slice( &slice_of_strings );
/// let expected = [
///     "test/test_b",
///     "test/test_b/test_c",
///     "test/test_a",
/// ].iter().map( | item | { format!( "{}", item, ) } ).collect::<Vec<String>>();
/// assert_eq!( result, expected, )
pub fn get_only_dirs_from_slice<T: Debug + Display>(arg_slice_of_strings: &[T]) -> Vec<String> {
    arg_slice_of_strings
        .iter()
        .map(|item| format!("{}", item))
        .filter(|item_string| PathBuf::from(item_string).is_dir())
        .collect::<Vec<String>>()
}

/// Returns a vec of only strings referencing files from a slice argument
/// # Arguments
/// * arg_slice_of_strings: [] of string-likes
/// # Examples
/// let slice_of_strings = [
///     "test/test_b",
///     "test/test_b/test_c",
///     "test/test_b/test_c/text_b_c_b.txt",
///     "test/test_b/test_c/text_b_c_a.txt",
///     "test/test_a",
///     "test/test_a/text_a_a.txt",
/// ];
/// let result = get_only_file_paths_from_slice( &slice_of_strings );
/// let expected = [
///     "test/test_b/test_c/text_b_c_b.txt",
///     "test/test_b/test_c/text_b_c_a.txt",
///     "test/test_a/text_a_a.txt",
/// ].iter().map( | item | { format!( "{}", item, ) } ).collect::<Vec<String>>();
/// assert_eq!( result, expected, )
pub fn get_only_file_paths_from_slice<T: Debug + Display>(
    arg_slice_of_strings: &[T],
) -> Vec<String> {
    arg_slice_of_strings
        .iter()
        .map(|item| format!("{}", item))
        .filter(|item_string| PathBuf::from(item_string).is_file())
        .collect::<Vec<String>>()
}

/// Returns a string path that is the result of combining a slice of string-like values
/// In case of a failure, this returns None
/// # Arguments
/// * arg_slice_of_strings: slice of string-likes
/// # Examples
/// let string_path = match get_path_joined( &[ "/A", "B", "C" ] ) {
///     Some( string_result ) => { string_result }
///     None => { panic!( "Failed to join strings into a path." ) }
/// };
/// string_path = "/A/B/C"
pub fn get_path_joined<T: Debug + Display>(arg_slice_of_strings: &[T]) -> Option<String> {
    match arg_slice_of_strings
        .iter()
        .map(|item| format!("{}", item,))
        .collect::<PathBuf>()
        .to_str()
    {
        Some(str_result) => Some(str_result.to_string()),
        None => None,
    }
}

/// Returns a string with the '~' expanded within the path
/// # Arguments
/// * arg_string_path: this is a string-like reference
/// # Examples
/// let string_path = get_path_with_tilde_expanded_if_necessary( "~/test" );
/// // string_path = '/Users/<user>/test
pub fn get_path_with_tilde_expanded_if_necessary<T: Debug + Display>(
    arg_string_path: &T,
) -> String {
    let mut string_path = format!("{}", arg_string_path,);
    if string_path.starts_with("~") {
        string_path = [
            shellexpand::tilde("~").to_string(),
            string_path.substring(1, string_path.len()).to_string(),
        ]
        .join("")
    }
    string_path
}

/// Returns a vec of string paths inside directory
/// In case of a failure, this returns an error explaining what happened
/// # Arguments
/// * arg_string_path: string-like path
/// # Examples
/// let string_path = "test";
/// let result = match get_paths_in_dir( &string_path ) {
///     Ok( vec_result ) => vec_result,
///     Err( err ) => panic!( "{}", err, )
/// };
/// let expected = [
///     "test/test_a",
///     "test/test_b",
/// ].iter().map( | item_str | { item_str.to_string() } ).collect::<Vec<String>>();
/// assert_eq!( result, expected )
pub fn get_paths_in_dir<T: Debug + Display>(arg_string_path: &T) -> Result<Vec<String>, String> {
    let slice_of_read_dirs = match std::fs::read_dir(&format!("{}", arg_string_path,)) {
        Ok(data_from_read_dir) => data_from_read_dir,
        Err(err) => {
            return Err([
                "Error: failed to read directory.".to_string(),
                format!("err = {}", err,),
                format!("arg_string_path_dir = {}", &arg_string_path,),
            ]
            .join("\n"))
        }
    };
    //
    // Convert slice_of_read_dirs to a vec of strings
    //
    let mut vec_to_return = vec![];
    for item_dir_entry_result in slice_of_read_dirs {
        vec_to_return.push(match &item_dir_entry_result {
            Ok(item_dir_entry_from_result) => match item_dir_entry_from_result.path().to_str() {
                Some(str_from_path_buf_to_return) => str_from_path_buf_to_return.to_string(),
                None => {
                    return Err([
                        "Error: failed to extract str from arg_path_buf".to_string(),
                        format!(
                            "item_dir_entry_from_result = {:?}",
                            &item_dir_entry_from_result,
                        ),
                    ]
                    .join("\n"))
                }
            },
            Err(err) => {
                return Err([
                    "Error: failed to extract item_dir_entry".to_string(),
                    format!("err = {}", err,),
                    format!("item_dir_entry_result = {:?}", &item_dir_entry_result,),
                ]
                .join("\n"))
            }
        })
    }
    Ok(vec_to_return)
}

/// Returns a vec of string paths inside directory
/// In case of a failure, this returns an error explaining what happened
/// # Arguments
/// * arg_string_path: string-like path
/// # Examples
/// let string_path = "test";
/// let result = match get_paths_in_dir_and_sub_dirs( &string_path ) {
///     Ok( vec_result ) => vec_result,
///     Err( err ) => panic!( "{}", err )
/// };
/// let expected = [
///     "test/test_b",
///     "test/test_b/test_c",
///     "test/test_b/test_c/text_b_c_b.txt",
///     "test/test_b/test_c/text_b_c_a.txt",
///     "test/test_a",
///     "test/test_a/text_a_a.txt",
/// ].iter().map( | item_str | { item_str.to_string() } ).collect::<Vec<String>>();
/// assert_eq!( result, expected )
pub fn get_paths_in_dir_and_sub_dirs<T: Debug + Display>(
    arg_string_path: &T,
) -> Result<Vec<String>, String> {
    let slice_of_read_dirs = match std::fs::read_dir(&format!("{}", arg_string_path,)) {
        Ok(data_from_read_dir) => data_from_read_dir,
        Err(err) => {
            return Err([
                "Error: failed to read directory.".to_string(),
                format!("err = {}", err,),
                format!("arg_string_path = {}", &arg_string_path,),
            ]
            .join("\n"))
        }
    };
    let mut vec_of_string_paths_files_contained_in_dir = vec![];
    for item_dir_entry_result in slice_of_read_dirs {
        vec_of_string_paths_files_contained_in_dir.push(match &item_dir_entry_result {
            Ok(item_dir_entry) => match item_dir_entry.path().to_str() {
                Some(str_from_path_buf) => str_from_path_buf.to_string(),
                None => {
                    return Err([
                        "Error: failed to extract str from arg_path_buf".to_string(),
                        format!("item_dir_entry = {:?}", &item_dir_entry,),
                    ]
                    .join("\n"))
                }
            },
            Err(err) => {
                return Err([
                    "Error: failed to extract item_dir_entry".to_string(),
                    format!("err = {}", err,),
                    format!("item_dir_entry_result = {:?}", &item_dir_entry_result,),
                ]
                .join("\n"))
            }
        })
    }
    //
    // Iterate through sub paths
    //
    let mut stack_of_dir_entries_to_process = Vec::from(vec_of_string_paths_files_contained_in_dir);
    //
    // Iterate over sub-paths and make sure nothing broke
    //
    let mut vec_to_return: Vec<String> = Vec::new();
    loop {
        match stack_of_dir_entries_to_process.pop() {
            Some(item_string_path_dir) => {
                //
                // Create string copy to push to vec
                //
                vec_to_return.push(item_string_path_dir.clone());
                //
                // Prep next iteration
                //
                let metadata_from_path = match std::fs::metadata(&item_string_path_dir) {
                    Ok(metadata_extracted) => metadata_extracted,
                    Err(err) => {
                        return Err([
                            "Error: failed to get meta data from arg_string_path.".to_string(),
                            format!("err = {:?}", err,),
                            format!("arg_string_path = {}", arg_string_path,),
                        ]
                        .join("\n"))
                    }
                };
                if metadata_from_path.is_dir() {
                    stack_of_dir_entries_to_process.extend({
                        let string_path_dir = format!("{}", item_string_path_dir,);
                        let read_dir_results = match std::fs::read_dir(&string_path_dir) {
                            Ok(data_from_read_dir) => data_from_read_dir,
                            Err(err) => {
                                return Err([
                                    "Error: failed to read directory.".to_string(),
                                    format!("err = {}", err,),
                                    format!("string_path_dir = {}", &string_path_dir,),
                                ]
                                .join("\n"))
                            }
                        };
                        let mut vec_of_results = vec![];
                        for item_dir_entry_result in read_dir_results {
                            //
                            // Get string path from dir entry result
                            //
                            vec_of_results.push(match &item_dir_entry_result {
                                Ok(item_dir_entry_from_result) => {
                                    match item_dir_entry_from_result.path().to_str() {
                                        Some(str_from_path_buf) => str_from_path_buf.to_string(),
                                        None => {
                                            return Err([
                                                "Error: failed to extract str from arg_path_buf"
                                                    .to_string(),
                                                format!(
                                                    "item_dir_entry_from_result.path() = {:?}",
                                                    &item_dir_entry_from_result.path(),
                                                ),
                                            ]
                                            .join("\n"))
                                        }
                                    }
                                }
                                Err(err) => {
                                    return Err([
                                        "Error: failed to extract item_dir_entry".to_string(),
                                        format!("err = {}", err,),
                                        format!(
                                            "item_dir_entry_result = {:?}",
                                            &item_dir_entry_result,
                                        ),
                                    ]
                                    .join("\n"))
                                }
                            })
                        }
                        vec_of_results
                    });
                }
            }
            //
            // Exit loop when we're out of sub directories
            //
            None => break,
        }
    }
    //
    // Return vec
    //
    Ok(vec_to_return)
}

/// Returns a vec of string paths, sorted by their depth, with the shortest first
/// # Arguments
/// * arg_slice_of_strings: [] of string-likes
/// # Examples
/// let slice_of_strings = [
///     "/A/B/C",
///     "/A",
///     "/A/B",
/// ];
/// let vec_of_strings = get_paths_sorted_by_size_starting_with_shortest( &slice_of_strings );
/// // vec_of_strings = [
/// //  "/A",
/// //  "/A/B",
/// //  "/A/B/C",
/// // ]
pub fn get_paths_sorted_by_size_starting_with_shortest<T: Debug + Display>(
    arg_slice_of_strings: &[T],
) -> Result<Vec<String>, String> {
    let vec_of_path_bufs =
        get_path_bufs_sorted_by_size_starting_with_shortest(&arg_slice_of_strings);
    let mut vec_to_return = vec![];
    for item_path_buf in vec_of_path_bufs {
        match item_path_buf.to_str() {
            Some(str_result) => vec_to_return.push(str_result.to_string()),
            None => {
                return Err([
                    "Error: failed to extract str from PathBuf".to_string(),
                    format!("item_path_buf = {:?}", item_path_buf,),
                ]
                .join("\n"))
            }
        }
    }
    Ok(vec_to_return)
}

/// Returns a vec of string paths inside directory
/// In case of a failure, this returns an error explaining what happened
/// # Arguments
/// * arg_string_path: string-like path
/// # Examples
/// let string_path = "test";
/// let result = match get_paths_to_only_dirs_in_dir_and_sub_dirs( &string_path ) {
///     Ok( vec_result ) => vec_result,
///     Err( err ) => panic!( "{}", err, )
/// };
/// let expected = [
///     "test/test_b",
///     "test/test_b/test_c",
///     "test/test_a",
/// ].iter().map(|item_str| {item_str.to_string()}).collect::<Vec<String>>();
/// assert_eq!( result, expected )
pub fn get_paths_to_only_dirs_in_dir_and_sub_dirs<T: Display>(
    arg_string_path_dir: &T,
) -> Result<Vec<String>, String> {
    Ok(
        match get_paths_in_dir_and_sub_dirs(&format!("{}", arg_string_path_dir,)) {
            Ok(result) => result,
            Err(err) => return Err(err),
        }
        .iter()
        .filter(|item_string_path| Path::new(&format!("{}", item_string_path,)).is_dir())
        .map(|item_string_path| item_string_path.clone())
        .collect::<Vec<String>>(),
    )
}

/// Returns a vec of string paths inside directory
/// In case of a failure, this returns an error explaining what happened
/// # Arguments
/// * arg_string_path: string-like path
/// # Examples
/// let string_path = "test";
/// let result = match get_paths_to_only_files_in_dir_and_sub_dirs( &string_path ) {
///     Ok( vec_result ) => { vec_result }
///     Err( err ) => { panic!( "{}", err, ) }
/// };
/// let expected = [
///     "test/test_b/test_c/text_b_c_b.txt",
///     "test/test_b/test_c/text_b_c_a.txt",
///     "test/test_a/text_a_a.txt",
/// ].iter().map( | item_str | { item_str.to_string() } ).collect::<Vec<String>>();
/// assert_eq!( result, expected )
pub fn get_paths_to_only_files_in_dir_and_sub_dirs<T: Display>(
    arg_string_path_dir: &T,
) -> Result<Vec<String>, String> {
    Ok(
        match get_paths_in_dir_and_sub_dirs(&format!("{}", arg_string_path_dir,)) {
            Ok(result) => result,
            Err(err) => return Err(err),
        }
        .iter()
        .filter(|item_string_path| Path::new(&format!("{}", item_string_path,)).is_file())
        .map(|item_string_path| item_string_path.clone())
        .collect::<Vec<String>>(),
    )
}

/// Returns a string that's a relative path after the prefix is removed
/// In case of a failure, this returns an error explaining what happened
/// # Arguments
/// * arg_string_path: string-like path
/// # Examples
/// let string_relative_path = match get_relative_path( &"/A/B/C/D", &"/A/B" ) {
///     Ok( string_result ) => { string_result }
///     Err( err ) => { panic!( "{}", err, ) }
/// };
/// // string_relative_path = "C/D"
pub fn get_relative_path<T1: Debug + Display, T2: Debug + Display>(
    arg_string_path: &T1,
    arg_string_path_root_prefix: &T2,
) -> Result<String, String> {
    match PathBuf::from(format!("{}", arg_string_path,))
        .strip_prefix(&PathBuf::from(format!("{}", arg_string_path_root_prefix,)))
    {
        Ok(path_result) => match path_result.to_str() {
            Some(str_result) => Ok(str_result.to_string()),
            None => {
                return Err([
                    "Error: failed getting str from path.".to_string(),
                    format!("path_relative (datatype: Path) = {:?}", path_result,),
                ]
                .join("\n"))
            }
        },
        Err(err) => {
            return Err([
                "Error: strip_prefix() failed.".to_string(),
                format!("err = {}", err,),
                format!("arg_string_path = {}", arg_string_path,),
                format!(
                    "arg_string_path_root_prefix = {}",
                    arg_string_path_root_prefix,
                ),
            ]
            .join("\n"))
        }
    }
}

/// Returns a vec resulting from splitting the path into substrings
/// Returns None in case of failure
/// # Arguments
/// * arg_string_path: a string-like path
/// # Examples
/// let vec_of_substrings = match get_vec_by_splitting_path( &"/A/B/C/D" ) {
///     Some( vec_result ) => { vec_result }
///     None => { panic!( "Failed to split path." ) }
/// };
/// // vec_of_substrings = [ "A", "B", "C", "D" ]
pub fn get_vec_by_splitting_path<T: Debug + Display>(arg_string_path: &T) -> Option<Vec<String>> {
    let mut vec_to_return = vec![];
    for item_os_str in PathBuf::from(format!("{}", arg_string_path,)).iter() {
        match item_os_str.to_str() {
            Some(str_result) => vec_to_return.push(str_result.to_string()),
            None => return None,
        }
    }
    Some(vec_to_return)
}
//
// Public - ( logic ) are / is
//
/// Returns true if both paths are pointing to the same dir / file on the disk
/// If relative paths are used, this fetches the cwd.
/// This assumes if a relative path is passed, the root dir of the working area is the project
/// # Arguments
/// * arg_string_path_left: string-like path to compare
/// * arg_string_right: string-like path to compare
/// * arg_string_path_working_dir: This serves as the 'root working directory' if relative paths are used
/// # Examples
/// let result = are_paths_the_same( &"/<project dir>/test", &"test" );
/// // result = true
pub fn are_paths_the_same<T1: Debug + Display, T2: Debug + Display, T3: Debug + Display>(
    arg_string_path_left: &T1,
    arg_string_path_right: &T2,
    arg_string_path_working_dir: &T3,
) -> bool {
    let path_buf_working_dir = PathBuf::from(format!("{}", arg_string_path_working_dir,));
    let path_buf_left = {
        let path_buf_from_arg = PathBuf::from(format!("{}", arg_string_path_left,));
        if path_buf_from_arg.is_absolute() {
            path_buf_from_arg
        } else {
            [&path_buf_working_dir, &path_buf_from_arg]
                .iter()
                .collect::<PathBuf>()
        }
    };
    let path_buf_right = {
        let path_buf_from_arg = PathBuf::from(format!("{}", arg_string_path_right,));
        if path_buf_from_arg.is_absolute() {
            PathBuf::from(format!("{}", arg_string_path_right,))
        } else {
            [&path_buf_working_dir, &path_buf_from_arg]
                .iter()
                .collect::<PathBuf>()
        }
    };
    path_buf_left == path_buf_right
}

/// Returns true if both paths are pointing to the same dir / file on the disk
/// If relative paths are used, this assumes the working directory is cwd
/// Due to the cwd fetch's potential for errors, this function requires unpacking
/// # Arguments
/// * arg_string_path: string-like path
/// # Examples
/// let result = match are_paths_the_same( &"/<project dir>/test", &"test" ) {
///     Ok( bool_result ) => { bool_result }
///     Err( err ) => { panic!( "{}", err, ) }
/// };
/// // result = true
pub fn are_paths_the_same_assume_cwd<T1: Debug + Display, T2: Debug + Display>(
    arg_string_path_left: &T1,
    arg_string_path_right: &T2,
) -> Result<bool, String> {
    Ok(are_paths_the_same(
        &arg_string_path_left,
        &arg_string_path_right,
        &match get_dir_cwd() {
            Ok(string_result) => string_result,
            Err(err) => return Err(err),
        },
    ))
}

/// Returns true if both paths are pointing to the same dir / file on the disk
/// If relative paths are used, this fetches the cwd.
/// If a relative path is used, this assumes the working directory is the project's root
/// # Arguments
/// * arg_string_path: string-like path
/// # Examples
/// let result = are_paths_the_same( &"/<project dir>/test", &"test" );
/// // result = true
pub fn are_paths_the_same_assume_project_dir<T1: Debug + Display, T2: Debug + Display>(
    arg_string_path_left: &T1,
    arg_string_path_right: &T2,
) -> bool {
    are_paths_the_same(
        &arg_string_path_left,
        &arg_string_path_right,
        &env!("CARGO_MANIFEST_DIR"),
    )
}

/// Returns true if the path argument has a parent, and false if not
/// # Arguments
/// * arg_string_path: string-like
/// # Examples
/// let result = has_parent( "/A/B/C" )
/// // result = true
pub fn has_parent<T: Debug + Display>(arg_string_path: &T) -> bool {
    match PathBuf::from(format!("{}", arg_string_path)).parent() {
        Some(_result) => true,
        None => false,
    }
}

/// Returns true if the string is an absolute path
/// # Arguments
/// * arg_string_path: string-like
/// # Examples
/// let result = is_absolute( &"/A/B/C" );
/// assert_eq!( result, true, );
pub fn is_absolute<T: Debug + Display>(arg_string_path: &T) -> bool {
    PathBuf::from(format!("{}", arg_string_path,)).is_absolute()
}

/// Returns bool is path is a directory
/// # Arguments
/// * arg_string_path: a string-like path
/// # Examples
/// let result = is_dir( &"/A/B/C/D" );
pub fn is_dir<T: Debug + Display>(arg_string_path: &T) -> bool {
    return PathBuf::from(format!("{}", arg_string_path,)).is_dir();
}

/// Returns bool is path is a directory
/// # Arguments
/// * arg_string_path: string-like path
/// # Examples
/// let result = is_existing_path( &"/A/B/C/D" );
pub fn is_existing_path<T: Debug + Display>(arg_string_path: &T) -> bool {
    return PathBuf::from(format!("{}", arg_string_path,)).exists();
}

/// Returns bool is path is a directory
/// # Arguments
/// * arg_string_path: string-like path
/// # Examples
/// let result = is_file( &"/A/B/C/D" );
pub fn is_file<T: Debug + Display>(arg_string_path: &T) -> bool {
    return PathBuf::from(format!("{}", arg_string_path,)).is_file();
}

/// Returns true if arg is type Path
/// # Arguments
/// * arg: any data type
/// # Examples
/// let result = is_path( &"/A/B/C/D" );
pub fn is_path_type<T>(_arg: &T) -> bool {
    std::any::type_name::<T>()
        .to_string()
        .ends_with("std::path::Path")
}

/// Returns true if arg is type PathBuf
/// # Arguments
/// * arg: any data type
/// # Examples
/// let result = is_path_buf( &"/A/B/C/D" );
pub fn is_path_buf_type<T>(_arg: &T) -> bool {
    std::any::type_name::<T>()
        .to_string()
        .ends_with("std::path::PathBuf")
}

/// Returns true if arg_string_path is inside arg_string_dir_parent
/// # Arguments
/// * arg_string_path: string-like
/// * arg_string_dir_parent: string-like
/// # Examples
/// let result = is_path_inside_dir_parent( &"/A/B/C", &"/A/B/C/D" );
pub fn is_path_inside_dir_parent<T1: Display, T2: Display>(
    arg_string_path: &T1,
    arg_string_dir_parent: &T2,
) -> bool {
    Path::new(&format!("{}", arg_string_path,)).starts_with(format!("{}", arg_string_dir_parent,))
}
//
// Public - raise error
//
/// Returns an error if one is detected. Otherwise, this returns None
/// # Argument
/// * arg_string_path: string-like
/// # Examples
/// let err = match raise_error_if_path_does_not_exist( &"/A/B/C" ) {
///     Ok( () ) => {},
///     Err( err ) => { panic!( "{:?}", err, ) }
/// };
pub fn raise_error_if_path_does_not_exist<T: Debug + Display>(
    arg_string_path: &T,
) -> Result<(), String> {
    if !Path::new(format!("{}", arg_string_path,).as_str()).exists() {
        return Err(
            [
                "Error: path does not exist.".to_string(),
                format!("arg_string_path = {}", arg_string_path,),
                match get_dir_ancestor_that_exists(&arg_string_path) {
                    Some(string_result) => {
                        format!("ancestor that actually exists = {}", string_result,)
                    }
                    None => format!("No existing ancestor exists."),
                },
            ]
            .join("\n"),
        );
    }
    Ok(())
}

/// Returns an error if arg_string_path points to a location outside the project.
/// Otherwise, this returns None.
/// # Arguments
/// * arg_string_path: string-like
/// # Examples
/// let err = match raise_error_if_path_is_not_in_project( &"/A/B/C" ) {
///     Ok( () ) => {}
///     Err( err ) => { panic!( "{:?}", err, ) }
/// };
pub fn raise_error_if_path_is_not_in_project<T: Debug + Display>(
    arg_string_path: &T,
) -> Result<(), String> {
    let path_buf_control = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
    let bool_raise_error = {
        let path_buf_from_arg = PathBuf::from(format!("{}", arg_string_path,));
        if path_buf_from_arg.is_absolute() {
            !path_buf_from_arg.starts_with(&path_buf_control)
        } else {
            ![&path_buf_control, &path_buf_from_arg]
                .iter()
                .collect::<PathBuf>()
                .exists()
        }
    };
    if bool_raise_error {
        return Err(
            [
                "Error: arg_string_path is either the project directory or outside it.".to_string(),
                format!("arg_string_path = {}", arg_string_path,),
                format!("path_buf_control = {:?}", path_buf_control,),
            ]
            .join("\n"),
        );
    }
    Ok(())
}

/// Returns an error if arg_string_path points to project directory.
/// Otherwise, this returns None.
/// # Arguments
/// * arg_string_path: string-like
/// # Examples
/// let err = match raise_error_if_path_points_to_project_root( &"/A/B/C" ) {
///     Ok( () ) => {},
///     Err( err ) => { panic!( "{:?}", err, ) }
/// };
pub fn raise_error_if_path_points_to_project_root<T: Display>(
    arg_string_path: &T,
) -> Result<(), String> {
    if Path::new(&format!("{}", arg_string_path,))
        == Path::new(&env!("CARGO_MANIFEST_DIR").to_string())
    {
        return Err(
            [
                "Error: arg_string_path points at project root directory.".to_string(),
                format!("arg_string_path = {}", arg_string_path,),
            ]
            .join("\n"),
        );
    }
    Ok(())
}

/// Returns an error if arg_string_path points to src within project.
/// Otherwise, this returns None.
/// If the path is relative, then the
/// # Arguments
/// * arg_string_path: string-like
/// # Examples
/// let err = match raise_error_if_path_points_to_src( &"/A/B/C" ) {
///     Ok( () ) => {}
///     Err( err ) => { panic!( "{:?}", err, ) }
/// };
pub fn raise_error_if_path_points_to_src<T: Debug + Display>(
    arg_string_path: &T,
) -> Result<(), String> {
    if are_paths_the_same_assume_project_dir(arg_string_path, &"src") {
        return Err(
            [
                "Error: arg_string_path points at the src directory.".to_string(),
                format!("arg_string_path = {}", arg_string_path,),
            ]
            .join("\n"),
        );
    }
    Ok(())
}

/// Returns an error if arg_string_path points to Cargo.toml within project.
/// Otherwise, this returns None.
/// # Arguments
/// * arg_string_path: string-like
/// # Examples
/// let err = match raise_error_if_path_points_to_cargo_toml( &"/A/B/C" ) {
///     Ok( () ) => {},
///     Err( err ) => { panic!( "{:?}", err, ) }
/// };
pub fn raise_error_if_path_points_to_cargo_toml<T: Debug + Display>(
    arg_string_path: &T,
) -> Result<(), String> {
    if are_paths_the_same_assume_project_dir(arg_string_path, &"Cargo.toml") {
        return Err(
            [
                "Error: arg_string_path points at Cargo.toml.".to_string(),
                format!("arg_string_path = {}", &arg_string_path,),
            ]
            .join("\n"),
        );
    }
    Ok(())
}

/// Returns an error if arg_string_path points at main.rs in the project.
/// Otherwise, this returns None.
/// # Arguments
/// * arg_string_path: string-like
/// # Examples
/// let err = match raise_error_if_path_points_to_main_rs( &"/A/B/C" ) {
///     Ok( ()) ) => {}
///     Err( err ) => { panic!( "{:?}", err, ) }
/// };
pub fn raise_error_if_path_points_to_main_rs<T: Debug + Display>(
    arg_string_path: &T,
) -> Result<(), String> {
    if are_paths_the_same_assume_project_dir(arg_string_path, &"src/main.rs") {
        return Err(
            [
                "Error: arg_string_path points at main.rs.".to_string(),
                format!("arg_string_path = {}", arg_string_path,),
            ]
            .join("\n"),
        );
    }
    Ok(())
}
//
// Public - get - from type
//
// Reminder: Don't need tests for these since they are straight type conversions.
//
/// Returns PathBuf created from a string-like argument
/// # Arguments
/// * arg_string: string-like
/// # Examples
/// let path_buf = get_path_buf_from_type_string( &str_or_string );
pub fn get_path_buf_from_type_string<T: Debug + Display>(arg_string: &T) -> PathBuf {
    PathBuf::from(format!("{}", arg_string,))
}

/// Returns a String extracted from DirEntry
/// In case of failure, this returns None
/// # Arguments
/// * arg_dir_entry: argument of type: &DirEntry
/// # Examples
/// let string_result = match get_string_from_type_dir_entry( &dir_entry ) {
///     Some( string_result ) => { string_result }
///     None => { panic!( "Failed to get string from DirEntry." ) }
/// };
pub fn get_string_from_type_dir_entry(arg_dir_entry: &DirEntry) -> Option<String> {
    match arg_dir_entry.path().to_str() {
        Some(str_result) => Some(str_result.to_string()),
        None => None,
    }
}

/// Returns String extracted from OsStr
/// Returns None in case of failure
/// # Arguments
/// * arg_osstr: argument of type: &OsStr
/// # Examples
/// let string_result = match get_string_from_type_dir_entry( &os_str ) {
///     Some( string_result ) => { string_result }
///     None => { panic!( "Failed to get string from OsStr." ) }
/// };
pub fn get_string_from_type_osstr(arg_osstr: &OsStr) -> Option<String> {
    match arg_osstr.to_str() {
        Some(str_result) => Some(str_result.to_string()),
        None => None,
    }
}

/// Returns String extracted from Path
/// Returns None in case of failure
/// # Arguments
/// * arg_path: argument of type: &Path
/// # Examples
/// let string_result = match get_string_from_type_dir_entry( &path_variable ) {
///     Some( string_result ) => { string_result }
///     None => { panic!( "Failed to get string from Path." ) }
/// };
pub fn get_string_from_type_path(arg_path: &Path) -> Option<String> {
    match arg_path.to_str() {
        Some(str_result) => Some(str_result.to_string()),
        None => None,
    }
}

/// Returns String extracted from PathBuf
/// Returns None in case of failure
/// # Arguments
/// * arg_path_buf: argument of type: &PathBuf
/// # Examples
/// let string_result = match get_string_from_type_dir_entry( &path_buf ) {
///     Some( string_result ) => { string_result }
///     None => { panic!( "Failed to get string from PathBuf." ) }
/// };
pub fn get_string_from_type_path_buf(arg_path_buf: &PathBuf) -> Option<String> {
    match arg_path_buf.to_str() {
        Some(str_result) => Some(str_result.to_string()),
        None => None,
    }
}
//
// Private
//
fn get_path_bufs_sorted_by_size_starting_with_shortest<T: Debug + Display>(
    arg_slice_of_strings: &[T],
) -> Vec<PathBuf> {
    let mut vec_of_path_bufs = arg_slice_of_strings
        .iter()
        .map(|item| PathBuf::from(format!("{}", item)))
        .collect::<Vec<PathBuf>>();
    vec_of_path_bufs.sort_by(|item_path_buf_left, item_path_buf_right| {
        item_path_buf_left.cmp(item_path_buf_right)
    });
    vec_of_path_bufs
}