@@ -53,7 +53,11 @@ follow-up PRs against this RFC.
53
53
* [ core::io] (stub)
54
54
* [ The std::io facade] (stub)
55
55
* [ std::env] (stub)
56
- * [ std::fs] (stub)
56
+ * [ std::fs]
57
+ * [ Free functions]
58
+ * [ Files]
59
+ * [ File kinds]
60
+ * [ File permissions]
57
61
* [ std::net] (stub)
58
62
* [ std::process] (stub)
59
63
* [ std::os]
@@ -708,7 +712,129 @@ throughout IO, we can go on to explore the modules in detail.
708
712
### ` std::fs `
709
713
[ std::fs ] : #stdfs
710
714
711
- > To be added in a follow-up PR.
715
+ The ` fs ` module will provide most of the functionality it does today,
716
+ but with a stronger cross-platform orientation.
717
+
718
+ Note that all path-consuming functions will now take an
719
+ ` AsPath ` -bounded parameter for ergonomic reasons (this will allow
720
+ passing in Rust strings and literals directly, for example).
721
+
722
+ #### Free functions
723
+ [ Free functions ] : #free-functions
724
+
725
+ ** Files** :
726
+
727
+ * ` copy ` . Take ` AsPath ` bound.
728
+ * ` rename ` . Take ` AsPath ` bound.
729
+ * ` remove_file ` (renamed from ` unlink ` ). Take ` AsPath ` bound.
730
+
731
+ * ` file_attr ` (renamed from ` stat ` ). Take ` AsPath ` bound. Yield a new
732
+ struct, ` FileAttr ` , with no public fields, but ` size ` , ` kind ` and
733
+ ` perm ` accessors. The various ` os::platform ` modules will offer
734
+ extension methods on this structure.
735
+
736
+ * ` set_perm ` (renamed from ` chmod ` ). Take ` AsPath ` bound, and a
737
+ ` FilePermissions ` value. The ` FilePermissions ` type will be revamped
738
+ as a struct with private implementation; see below.
739
+
740
+ ** Directories** :
741
+
742
+ * ` make_dir ` (renamed from ` mkdir ` ). Take ` AsPath ` bound.
743
+ * ` make_dir_all ` (renamed from ` mkdir_recursive ` ). Take ` AsPath ` bound.
744
+ * ` read_dir ` (renamed from ` readdir ` ). Take ` AsPath ` bound. Yield a
745
+ newtypes iterator, which yields a new type ` DirEntry ` which has an
746
+ accessor for ` Path ` , but will eventually provide other information
747
+ as well (possibly via platform-specific extensions).
748
+ * ` remove_dir ` (renamed from ` rmdir ` ). Take ` AsPath ` bound.
749
+ * ` remove_dir_all ` (renamed from ` rmdir_recursive ` ). Take
750
+ ` AsPath ` bound.
751
+ * ` walk_dir ` . Take ` AsPath ` bound. Yield an iterator over ` IoResult<DirEntry> ` .
752
+
753
+ ** Links** :
754
+
755
+ * ` hard_link ` (renamed from ` link ` ). Take ` AsPath ` bound.
756
+ * ` sym_link ` (renamed from ` symlink ` ). Take ` AsPath ` bound.
757
+ * ` read_link ` (renamed form ` readlink ` ). Take ` AsPath ` bound.
758
+
759
+ #### Files
760
+ [ Files ] : #files
761
+
762
+ The ` File ` type will largely stay as it is today, except that it will
763
+ use the ` AsPath ` bound everywhere.
764
+
765
+ The ` stat ` method will be renamed to ` attr ` , yield a ` FileAttr ` , and
766
+ take ` &self ` .
767
+
768
+ The ` fsync ` method will be renamed to ` flush ` , and ` datasync ` will be
769
+ renamed to ` flush_data ` . (Although the latter is not available on
770
+ Windows, it can be considered an optimization for ` flush ` and on
771
+ Windows behave identically to ` flush ` , just as it does on some Unix
772
+ filesystems.)
773
+
774
+ The ` path ` method wil remain ` #[unstable] ` , as we do not yet want to
775
+ commit to its API.
776
+
777
+ The ` open_mode ` function will take an ` OpenOptions ` struct, which will
778
+ encompass today's ` FileMode ` and ` FileAccess ` and support a
779
+ builder-style API.
780
+
781
+ #### File kinds
782
+ [ File kinds ] : #file-kinds
783
+
784
+ The ` FileType ` module will be renamed to ` FileKind ` , and the
785
+ underlying ` enum ` will be hidden (to allow for platform differences
786
+ and growth). It will expose at least ` is_file ` and ` is_dir ` ; the other
787
+ methods need to be audited for compatibility across
788
+ platforms. Platform-specific kinds will be relegated to extension
789
+ traits in ` std::os::platform ` .
790
+
791
+ #### File permissions
792
+ [ File permissions ] : #file-permissions
793
+
794
+ The permission models on Unix and Windows vary greatly -- even between
795
+ different filesystems within the same OS. Rather than offer an API
796
+ that has no meaning on some platforms, we will initially provide a
797
+ very limited ` FilePermissions ` structure in ` std::fs ` , and then rich
798
+ extension traits in ` std::os::unix ` and ` std::os::windows ` . Over time,
799
+ if clear cross-platform patterns emerge for richer permissions, we can
800
+ grow the ` FilePermissions ` structure.
801
+
802
+ On the Unix side, the constructors and accessors for ` FilePermissions `
803
+ will resemble the flags we have today; details are left to the implementation.
804
+
805
+ On the Windows side, initially there will be no extensions, as Windows
806
+ has a very complex permissions model that will take some time to build
807
+ out.
808
+
809
+ For ` std::fs ` itself, ` FilePermissions ` will provide constructors and
810
+ accessors for "world readable" -- and that is all. At the moment, that
811
+ is all that is known to be compatible across the platforms that Rust
812
+ supports.
813
+
814
+ #### ` PathExt `
815
+ [ PathExt ] : #pathext
816
+
817
+ This trait will essentially remain stay as it is (renamed from
818
+ ` PathExtensions ` ), following the same changes made to ` fs ` free functions.
819
+
820
+ #### Items to move to ` os::platform `
821
+
822
+ * ` change_file_times ` will move to ` os::unix ` and remain ` #[unstable] `
823
+ * for now* (cf ` SetFileTime ` on Windows). Eventually we will add back
824
+ a cross-platform function, when we have grown a notion of time in
825
+ ` std ` and have a good compatibility story across all platforms.
826
+
827
+ * ` lstat ` will move to ` os::unix ` and remain ` #[unstable] ` * for now*
828
+ since it is not yet implemented for Windows.
829
+
830
+ * ` chown ` will move to ` os::unix ` (it currently does * nothing* on
831
+ Windows), and eventually ` os::windows ` will grow support for
832
+ Windows's permission model. If at some point a reasonable
833
+ intersection is found, we will re-introduce a cross-platform
834
+ function in ` std::fs ` .
835
+
836
+ * In general, offer all of the ` stat ` fields as an extension trait on
837
+ ` FileAttr ` (e.g. ` os::unix::FileAttrExt ` ).
712
838
713
839
### ` std::net `
714
840
[ std::net ] : #stdnet
0 commit comments