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
use std::fs::{File};
use crate::date_time_ext::DateTimeExt;
use crate::directory_ext_impl::DirectoryExtImpl;
use crate::file_ext_impl::FileExtImpl;
use crate::path_ext_impl::PathExtImpl;
use crate::symbol::SYMBOL;
use crate::symlink_ext_impl::SymlinkExtImpl;
use crate::user_ext_impl::UserExtImpl;

#[cfg(test)]
mod tests;
mod date_time_ext;
mod symbol;
mod file_ext_impl;
mod path_ext_impl;
mod directory_ext_impl;
mod symlink_ext_impl;
mod user_ext_impl;
mod filter_string;

pub struct FileExt;

impl FileExt {

    /// Returns portion of a file of specified range. Range described as starting from byte M up to byte N.
    /// # Examples
    ///
    /// ```
    /// use file_ext::FileExt;
    /// #[test]
    /// fn partial_read() {
    ///     let path = "test/index.html";
    ///     let file_raw_bytes = FileExt::read_file_partially(path, 4, 10).unwrap();
    ///     let content = String::from_utf8(file_raw_bytes).unwrap();
    ///
    ///     let expected_content = "CTYPE h";
    ///
    ///     assert_eq!(expected_content, content);
    /// }
    /// ```
    pub fn read_file_partially(filepath: &str, start: u64, end: u64) -> Result<Vec<u8>, String> {
        FileExtImpl::read_file_partially(filepath, start, end)
    }

    /// Returns file content
    /// # Examples
    ///
    /// ```
    ///  use file_ext::FileExt;
    ///  #[test]
    ///  fn file_content() {
    ///      let path = "test/index.html";
    ///      let file_raw_bytes = FileExt::read_file(path).unwrap();
    ///      let content = String::from_utf8(file_raw_bytes).unwrap();
    ///  
    ///      let content_escaped_newline_carriage_return = str::replace(content.as_str(), "\r\n", "\n");
    ///
    ///      let expected_content = "<!DOCTYPE html>\n<html lang=\"en\">\n<head>\n    <meta charset=\"UTF-8\">\n    <title>Title</title>\n</head>\n<body>\n\n</body>\n</html>";
    ///
    ///      assert_eq!(expected_content, content_escaped_newline_carriage_return);
    ///  }
    /// ```
    pub fn read_file(filepath: &str) -> Result<Vec<u8>, String> {
        FileExtImpl::read_file(filepath)
    }

    /// Returns file modification timestamp as nanoseconds in Unix epoch
    /// # Examples
    ///
    /// ```
    ///  use std::{thread, time};
    ///  use file_ext::FileExt;
    ///  #[test]
    ///  fn modification_timestamp() {
    ///
    ///      let content = "data".as_bytes();
    ///      let path = "modification_timestamp-test.content";
    ///
    ///      FileExt::create_file(path).unwrap();
    ///      FileExt::write_file(path, content).unwrap();
    ///
    ///      let does_exist = FileExt::does_file_exist(path);
    ///      assert!(does_exist);
    ///
    ///      let modified_timestamp = FileExt::file_modified_utc(path).unwrap();
    ///
    ///      let one_second = time::Duration::from_secs(1);
    ///      thread::sleep(one_second);
    ///
    ///      FileExt::write_file(path, "\nnewline and some data".as_bytes()).unwrap();
    ///
    ///      let after_update_modified_timestamp = FileExt::file_modified_utc(path).unwrap();
    ///      assert!(after_update_modified_timestamp > modified_timestamp);
    ///
    ///
    ///      FileExt::delete_file(path).unwrap();
    ///      let doesnt_exist = !FileExt::does_file_exist(path);
    ///      assert!(doesnt_exist);
    ///  }
    /// ```
    pub fn file_modified_utc(filepath: &str) -> Result<u128, String> {
        let boxed_open = File::open(filepath);
        if boxed_open.is_err() {
            let error_msg = boxed_open.err().unwrap();
            let error = format!("<p>Unable to open file: {}</p> <p>error: {}</p>", filepath, error_msg);
            return Err(error)
        }

        let file : File = boxed_open.unwrap();
        let boxed_metadata = file.metadata();
        if boxed_metadata.is_err() {
            let error_msg = boxed_metadata.err().unwrap();
            let error = format!("<p>Unable to open file: {}</p> <p>error: {}</p>", filepath, error_msg);
            return Err(error)
        }
        let metadata = boxed_metadata.unwrap();
        let boxed_last_modified_time = metadata.modified();
        if boxed_last_modified_time.is_err() {
            let error_msg = boxed_last_modified_time.err().unwrap();
            let error = format!("<p>Unable to open file: {}</p> <p>error: {}</p>", filepath, error_msg);
            return Err(error)
        }
        let modified_time = boxed_last_modified_time.unwrap();
        let nanos = DateTimeExt::_system_time_to_unix_nanos(modified_time);
        Ok(nanos)
    }

    #[cfg(target_family = "unix")]
    /// # Examples
    ///
    /// ```
    /// use file_ext::FileExt;
    /// #[test]
    /// fn unix_path_delimiter() {
    ///     let expected = SYMBOL.slash.to_string();
    ///     let actual = FileExt::get_path_separator();
    /// }
    /// ```
    pub fn get_path_separator() -> String {
        PathExtImpl::get_path_separator()
    }

    #[cfg(target_family = "windows")]
    /// # Examples
    ///
    /// ```
    /// use file_ext::FileExt;
    /// #[test]
    /// fn unix_path_delimiter() {
    ///     let expected = SYMBOL.reverse_slash.to_string();
    ///     let actual = FileExt::get_path_separator();
    /// }
    /// ```
    pub fn get_path_separator() -> String { PathExtImpl::get_path_separator() }

    /// Will return absolute file path to the working directory
    /// # Examples
    ///
    /// ```
    /// use file_ext::FileExt;
    /// #[test]
    /// fn absolute_path_to_working_directory() {
    ///     let boxed_path = FileExt::working_directory();
    ///     assert!(boxed_path.is_ok());
    ///     let path = boxed_path.unwrap();
    /// }
    /// ```
    pub fn working_directory() -> Result<String, String> {
        PathExtImpl::working_directory()
    }


    /// Will return absolute file path to the working directory. Same as working_directory function. Kept here to preserve backward compatability.
    /// # Examples
    ///
    /// ```
    /// use file_ext::FileExt;
    /// #[test]
    /// fn absolute_path_to_working_directory() {
    ///     let boxed_path = FileExt::absolute_path_to_working_directory();
    ///     assert!(boxed_path.is_ok());
    ///     let path = boxed_path.unwrap();
    /// }
    /// ```
    pub fn absolute_path_to_working_directory() -> Result<String, String> {
        PathExtImpl::working_directory()
    }


    /// Will return absolute working directory path appended to the given string
    /// # Examples
    ///
    /// ```
    /// use file_ext::FileExt;
    /// #[test]
    /// fn absolute_path_to_working_directory() {
    ///     let boxed_path = FileExt::get_static_filepath("");
    ///     assert!(boxed_path.is_ok());
    ///     let path = boxed_path.unwrap();
    /// }
    /// ```
    pub fn get_static_filepath(path: &str) -> Result<String, String> {
        let boxed_working_directory = PathExtImpl::absolute_path_to_working_directory();
        if boxed_working_directory.is_err() {
            let message = boxed_working_directory.err().unwrap();
            return Err(message)
        }

        let working_directory = boxed_working_directory.unwrap();
        let absolute_path = [working_directory, path.to_string()].join(SYMBOL.empty_string);
        Ok(absolute_path)
    }

    /// Will try to read from file. If file does not exist, will create and write to it given byte array
    /// # Examples
    ///
    /// ```
    ///  use file_ext::FileExt;
    ///  #[test]
    ///  fn read_or_create_and_write() {
    ///      let content = "data".as_bytes();
    ///      let tmp_folder = FileExt::get_temp_folder_path().unwrap();
    ///
    ///      let path = [tmp_folder, "test.txt".to_string()].join(FileExt::get_path_separator().as_str());
    ///
    ///      let doesnt_exist = !FileExt::does_file_exist(path.as_str());
    ///      assert!(doesnt_exist);
    ///
    ///      FileExt::read_or_create_and_write(path.as_str(), content).unwrap();
    ///
    ///      let does_exist = FileExt::does_file_exist(path.as_str());
    ///      assert!(does_exist);
    ///
    ///      let new_content = "updated data".as_bytes();
    ///      FileExt::read_or_create_and_write(path.as_str(), new_content).unwrap();
    ///
    ///      let file_content = FileExt::read_file(path.as_str()).unwrap();
    ///      assert_eq!(content, file_content);
    ///
    ///      FileExt::delete_file(path.as_str()).unwrap();
    ///      let doesnt_exist = !FileExt::does_file_exist(path.as_str());
    ///      assert!(doesnt_exist);
    ///  }
    /// ```
    pub fn read_or_create_and_write(path: &str, content: &[u8]) -> Result<Vec<u8>, String> {
        FileExtImpl::read_or_create_and_write(path, content)
    }

    /// Will create a file on the path
    /// # Examples
    ///
    /// ```
    /// use file_ext::FileExt;
    /// #[test]
    /// fn file_creation_deletion() {
    ///     let path = "test/file-creation.txt";
    ///
    ///     let exists = FileExt::does_file_exist(path);
    ///     assert!(!exists);
    ///
    ///     FileExt::create_file(path).unwrap();
    ///
    ///     let content = FileExt::read_file(path).unwrap();
    ///     assert_eq!(content.len(), 0);
    ///
    ///     FileExt::delete_file(path).unwrap();
    ///
    ///     let exists = FileExt::does_file_exist(path);
    ///     assert!(!exists);
    /// }
    /// ```
    pub fn create_file(path: &str) -> Result<(), String>  {
        FileExtImpl::create_file(path)
    }

    /// Returns boolean indicating file existence on the path
    /// # Examples
    ///
    /// ```
    /// use file_ext::FileExt;
    /// #[test]
    /// fn file_exists() {
    ///     let path = "test/index_rewrite";
    ///     let exists = FileExt::does_file_exist(path);
    ///     assert!(exists);
    /// }
    /// ```
    pub fn does_file_exist(path: &str) -> bool {
        FileExtImpl::does_file_exist(path)
    }

    /// Returns boolean indicating directory existence on the path
    /// # Examples
    ///
    /// ```
    /// use file_ext::FileExt;
    /// #[test]
    /// fn directory_exists() {
    ///     let path = "test";
    ///     let exists = FileExt::does_directory_exist(path);
    ///     assert!(exists);
    /// }
    /// ```
    pub fn does_directory_exist(path: &str) -> bool {
        DirectoryExtImpl::does_directory_exist(path)
    }


    /// Will create a new directory on specified path
    /// # Examples
    ///
    /// ```
    ///  use file_ext::FileExt;
    ///  #[test]
    ///  fn new_directory_create_delete() {
    ///      let path = "new_directory";
    ///
    ///      let boxed_create = FileExt::create_directory(path);
    ///      assert!(boxed_create.is_ok());
    ///
    ///      assert!(FileExt::does_directory_exist(path));
    ///
    ///      let boxed_delete = FileExt::delete_directory(path);
    ///      assert!(boxed_delete.is_ok());
    ///  }
    /// ```
    pub fn create_directory(path: &str) -> Result<(), String> {
        DirectoryExtImpl::create_directory(path)
    }

    /// Will delete directory and all of the content on specified path (won't follow symlinks)
    /// # Examples
    ///
    /// ```
    ///  use file_ext::FileExt;
    ///  #[test]
    ///  fn new_directory_create_delete() {
    ///      let path = "new_directory";
    ///
    ///      let boxed_create = FileExt::create_directory(path);
    ///      assert!(boxed_create.is_ok());
    ///
    ///      assert!(FileExt::does_directory_exist(path));
    ///
    ///      let boxed_delete = FileExt::delete_directory(path);
    ///      assert!(boxed_delete.is_ok());
    ///  }
    /// ```
    pub fn delete_directory(path: &str) -> Result<(), String> {
        DirectoryExtImpl::delete_directory(path)
    }


    /// Returns boolean indicating symlink existence on the path
    /// # Examples
    ///
    /// ```
    /// use file_ext::FileExt;
    /// #[test]
    /// fn symlink_exists() {
    ///   let symlink_path = ["test", "index-link2"].join(FileExt::get_path_separator().as_str());
    ///
    ///   if FileExt::does_symlink_exist(symlink_path.as_str()) {
    ///     FileExt::delete_file(symlink_path.as_str()).unwrap();
    ///   }
    ///
    ///   let path = [SYMBOL.empty_string, "test", SYMBOL.empty_string].join(FileExt::get_path_separator().as_str());
    ///   let path_prefix = FileExt::get_static_filepath(path.as_str()).unwrap();
    ///   let points_to = [path_prefix.to_string(), "index.html".to_string()].join("");
    ///
    ///   let boxed_symlink = FileExt::create_symlink(
    ///     path_prefix.as_str(),
    ///     "index-link2",
    ///     points_to.as_str()
    ///   );
    ///
    ///
    ///   assert!(boxed_symlink.is_ok());
    ///
    ///   let symlink_created = FileExt::does_symlink_exist(symlink_path.as_str());
    ///   assert!(symlink_created);
    ///
    ///   let actual_points_to = FileExt::symlink_points_to(symlink_path.as_str()).unwrap();
    ///   assert_eq!(points_to, actual_points_to);
    ///
    ///   FileExt::delete_file(symlink_path.as_str()).unwrap();
    /// }
    /// ```
    pub fn does_symlink_exist(path: &str) -> bool {
        SymlinkExtImpl::does_symlink_exist(path)
    }

    /// Returns absolute path, symlink points to.
    /// Takes 2 parameters: path to the directory, where symlink is located and where symlink points to
    /// # Examples
    ///
    /// ```
    /// use file_ext::FileExt;
    /// #[test]
    /// fn resolve_symlink_path() {
    ///    let base_dir = "/home/someuser/folder/subfolder/subsubfolder";
    ///    let symlink_points_to = "../../subfolder2/subsubfolder2";
    ///
    ///    let expected_path = "/home/someuser/folder/subfolder2/subsubfolder2";
    ///    let actual_path = FileExt::resolve_symlink_path(base_dir, symlink_points_to).unwrap();
    ///
    ///    assert_eq!(expected_path, actual_path);
    /// }
    /// ```
    pub fn resolve_symlink_path(symlink_directory: &str, symlink_points_to: &str) -> Result<String, String> {
        SymlinkExtImpl::resolve_symlink_path(symlink_directory, symlink_points_to)
    }

    /// Will write given byte array to a file on the path
    /// # Examples
    /// ```
    ///  use file_ext::FileExt;
    /// #[test]
    ///  fn write() {
    ///      let filename = "write-test.content";
    ///      FileExt::create_file(filename).unwrap();
    ///
    ///      let expected_content = "<!DOCTYPE html>\n<html lang=\"en\">\n<head>\n    <meta charset=\"UTF-8\">\n    <title>Title</title>\n</head>\n<body>\n\n</body>\n</html>";
    ///      FileExt::write_file(filename, expected_content.as_bytes()).unwrap();
    ///
    ///      let actual = FileExt::read_file(filename).unwrap();
    ///      assert_eq!(actual, expected_content.as_bytes());
    ///
    ///  }
    /// ```
    pub fn write_file(path: &str, file_content: &[u8]) -> Result<(), String> {
        FileExtImpl::write_file(path, file_content)
    }

    /// Will delete file on a given path
    /// # Examples
    ///
    /// ```
    /// use file_ext::FileExt;
    /// #[test]
    /// fn file_creation_deletion() {
    ///     let path = "test/file-creation.txt";
    ///
    ///     let exists = FileExt::does_file_exist(path);
    ///     assert!(!exists);
    ///
    ///     FileExt::create_file(path).unwrap();
    ///
    ///     let content = FileExt::read_file(path).unwrap();
    ///     assert_eq!(content.len(), 0);
    ///
    ///     FileExt::delete_file(path).unwrap();
    ///
    ///     let exists = FileExt::does_file_exist(path);
    ///     assert!(!exists);
    /// }
    /// ```
    pub fn delete_file(path: &str) -> Result<(), String> {
        FileExtImpl::delete_file(path)
    }

    /// Will create symlink on path `symlink_path` with the specified name `symlink_name`.
    /// Symlink will point to specific file or directory `symlink_points_to`. Paths are absolute.
    /// # Examples
    /// ```
    /// use file_ext::FileExt;
    /// #[test]
    ///fn symlink_creation() {
    ///    let symlink_path = "test/index-link";
    ///
    ///    if FileExt::does_symlink_exist(symlink_path) {
    ///        FileExt::delete_file(symlink_path).unwrap();
    ///    }
    ///
    ///    let path_prefix = FileExt::get_static_filepath("/test/").unwrap();
    ///    let points_to = [path_prefix.to_string(), "index.html".to_string()].join("");
    ///
    ///    let boxed_symlink = FileExt::create_symlink(
    ///        path_prefix.as_str(),
    ///        "index-link",
    ///        points_to.as_str());
    ///
    ///     assert!(boxed_symlink.is_ok());
    ///
    ///     let symlink_created = FileExt::does_symlink_exist(symlink_path);
    ///     assert!(symlink_created);
    ///
    ///     let actual_points_to = FileExt::symlink_points_to(symlink_path).unwrap();
    ///     assert_eq!(points_to, actual_points_to);
    ///
    ///     FileExt::delete_file(symlink_path).unwrap();
    ///}
    ///```
    #[cfg(target_family = "unix")]
    pub fn create_symlink(symlink_path: &str, symlink_name: &str, symlink_points_to: &str) -> Result<(), String> {
        SymlinkExtImpl::create_symlink(symlink_path, symlink_name, symlink_points_to)
    }


    /// Will create symlink on path `symlink_path` with the specified name `symlink_name`.
    /// Symlink will point to specific file or directory `symlink_points_to`. Paths are absolute.
    /// # Examples
    /// ```
    /// use file_ext::FileExt;
    /// #[test]
    ///fn symlink_creation() {
    ///    let symlink_path = "test/index-link";
    ///
    ///    if FileExt::does_symlink_exist(symlink_path) {
    ///        FileExt::delete_file(symlink_path).unwrap();
    ///    }
    ///
    ///    let path_prefix = FileExt::get_static_filepath("/test/").unwrap();
    ///    let points_to = [path_prefix.to_string(), "index.html".to_string()].join("");
    ///
    ///    let boxed_symlink = FileExt::create_symlink(
    ///        path_prefix.as_str(),
    ///        "index-link",
    ///        points_to.as_str());
    ///
    ///        assert!(boxed_symlink.is_ok());
    ///
    ///        let symlink_created = FileExt::does_symlink_exist(symlink_path);
    ///        assert!(symlink_created);
    ///
    ///        let actual_points_to = FileExt::symlink_points_to(symlink_path).unwrap();
    ///        assert_eq!(points_to, actual_points_to);
    ///
    ///        FileExt::delete_file(symlink_path).unwrap();
    ///}
    ///```
    #[cfg(target_family = "windows")]
    pub fn create_symlink(symlink_path: &str, symlink_name: &str, symlink_points_to: &str) -> Result<(), String> {
        SymlinkExtImpl::create_symlink(symlink_path, symlink_name, symlink_points_to)
    }

    /// Checks if the file is symlink
    /// # Examples
    ///
    /// ```
    /// use file_ext::FileExt;
    /// #[test]
    /// fn is_link() {
    ///     let path: String = ["test", "index_rewrite"].join(&FileExt::get_path_separator());
    ///     let is_symlink = FileExt::is_symlink(path.as_str()).unwrap();
    ///     assert!(is_symlink);
    /// }
    /// ```
    pub fn is_symlink(path: &str) -> Result<bool, String> {
        SymlinkExtImpl::is_symlink(path)
    }

    /// Returns path to a file, symlink points to
    /// # Examples
    ///
    /// ```
    /// use file_ext::FileExt;
    /// #[test]
    /// fn link_points_to() {
    ///     let path: String = ["test", "index_rewrite"].join(&FileExt::get_path_separator());
    ///     let points_to = FileExt::symlink_points_to(path.as_str()).unwrap();
    ///     assert_eq!("index.html", points_to);
    /// }
    /// ```
    pub fn symlink_points_to(path: &str) -> Result<String, String> {
        SymlinkExtImpl::symlink_points_to(path)
    }

    /// Builds a path from a given node list
    /// # Examples
    ///
    /// ```
    /// use file_ext::FileExt;
    ///
    /// #[test]
    /// #[cfg(target_family = "unix")]
    /// fn build_path() {
    ///     let root = FileExt::root();
    ///     let folder_up = FileExt::folder_up();
    ///
    ///     let node_list =
    ///         [
    ///             root.as_str(),
    ///             "home",
    ///             "someuser",
    ///             "folder",
    ///             "subfolder",
    ///             "subsubfolder",
    ///         ];
    ///
    ///     let another_node_list =
    ///         [
    ///             folder_up.as_str(),
    ///             folder_up.as_str(),
    ///             "subfolder2",
    ///             "subsubfolder2",
    ///         ];
    ///     let path = PathExtImpl::build_path(&node_list);
    ///     let another_path = PathExtImpl::build_path(&another_node_list);
    ///
    ///     assert_eq!("/home/someuser/folder/subfolder/subsubfolder", path);
    ///     assert_eq!("../../subfolder2/subsubfolder2", another_path);
    /// }
    ///
    ///
    /// #[test]
    /// #[cfg(target_family = "windows")]
    /// fn build_path() {
    ///     let root = FileExt::root();
    ///     let folder_up = FileExt::folder_up();
    ///
    ///     let node_list =
    ///         [
    ///             root.as_str(),
    ///             "Users",
    ///             "someuser",
    ///             "folder",
    ///             "subfolder",
    ///             "subsubfolder",
    ///         ];
    ///
    ///     let path = PathExtImpl::build_path(&node_list);
    ///
    ///     assert_eq!("C:\\Users\\someuser\\folder\\subfolder\\subsubfolder", path);
    /// }
    /// ```
    pub fn build_path(list: &[&str]) -> String {
        PathExtImpl::build_path(list)
    }

    /// Root node of the system. It is meant to be used in `build_path` function.
    /// On Linux and macOS `build_path` function will evaluate it to `/`,
    /// on Windows it will be `C:`
    pub fn root() -> String {
        PathExtImpl::root()
    }


    /// Folder up, or `..`. It is meant to be used in `build_path` function.
    pub fn folder_up() -> String {
        PathExtImpl::folder_up()
    }

    /// Returns name of the user running the process
    /// # Examples
    ///
    /// ```
    ///  use file_ext::FileExt;
    ///  #[test]
    ///  #[cfg(target_family = "unix")]
    ///  fn current_user() {
    ///      let boxed_user = FileExt::get_current_user();
    ///      assert!(boxed_user.is_ok());
    ///
    ///      let user = boxed_user.unwrap();
    ///  }
    /// ```
    #[cfg(target_family = "unix")]
    pub fn get_current_user() -> Result<String, String> {
        UserExtImpl::get_current_user()
    }

    /// Returns name of the user running the process
    /// # Examples
    ///
    /// ```
    ///  use file_ext::FileExt;
    ///  #[test]
    ///  #[cfg(target_family = "windows")]
    ///  fn current_user() {
    ///      let boxed_user = FileExt::get_current_user();
    ///      assert!(boxed_user.is_ok());
    ///
    ///      let user = boxed_user.unwrap();
    ///  }
    /// ```
    #[cfg(target_family = "windows")]
    pub fn get_current_user() -> Result<String, String> {
        UserExtImpl::get_current_user()
    }

    /// Returns domain of the user running the process
    /// # Examples
    ///
    /// ```
    ///  use file_ext::FileExt;
    ///  #[test]
    ///  #[cfg(target_family = "windows")]
    ///  fn current_user() {
    ///      let boxed_user_domain = FileExt::get_current_user_domain();
    ///      assert!(boxed_user_domain.is_ok());
    ///
    ///      let domain = boxed_user_domain.unwrap();
    ///  }
    /// ```
    #[cfg(target_family = "windows")]
    pub fn get_current_user_domain() -> Result<String, String> {
        UserExtImpl::get_current_user_domain()
    }

    /// Returns path to the temporary folder
    /// # Examples
    ///
    /// ```
    ///  use file_ext::FileExt;
    ///  #[test]
    ///  #[cfg(target_family = "windows")]
    ///  fn temp_folder() {
    ///      let temp_folder_path = FileExt::get_temp_folder_path().unwrap();
    ///      assert!(temp_folder_path.starts_with("C:\\Users\\"));
    ///      assert!(temp_folder_path.ends_with("\\AppData\\Local\\Temp"));
    ///  }
    /// ```
    #[cfg(target_family = "windows")]
    pub fn get_temp_folder_path() -> Result<String, String>{
        PathExtImpl::get_temp_folder_path()
    }

    /// Returns path to the temporary folder
    /// # Examples
    ///
    /// ```
    ///  use file_ext::FileExt;
    ///  #[test]
    ///  #[cfg(target_family = "unix")]
    ///  fn temp_folder() {
    ///      let temp_folder_path = FileExt::get_temp_folder_path().unwrap();
    ///      assert_eq!(temp_folder_path, "/tmp")
    ///  }
    /// ```
    #[cfg(target_family = "unix")]
    pub fn get_temp_folder_path() -> Result<String, String>{
        PathExtImpl::get_temp_folder_path()
    }
}