11use std:: fs;
22use std:: path:: Path ;
33
4- /// A wrapper around [`std::fs::remove_file`] which includes the file path in the panic message..
4+ /// A wrapper around [`std::fs::remove_file`] which includes the file path in the panic message.
55#[ track_caller]
66pub fn remove_file < P : AsRef < Path > > ( path : P ) {
77 fs:: remove_file ( path. as_ref ( ) )
@@ -18,21 +18,28 @@ pub fn copy<P: AsRef<Path>, Q: AsRef<Path>>(from: P, to: Q) {
1818 ) ) ;
1919}
2020
21- /// A wrapper around [`std::fs::File::create`] which includes the file path in the panic message..
21+ /// A wrapper around [`std::fs::File::create`] which includes the file path in the panic message.
2222#[ track_caller]
2323pub fn create_file < P : AsRef < Path > > ( path : P ) {
2424 fs:: File :: create ( path. as_ref ( ) )
2525 . expect ( & format ! ( "the file in path \" {}\" could not be created" , path. as_ref( ) . display( ) ) ) ;
2626}
2727
28- /// A wrapper around [`std::fs::read`] which includes the file path in the panic message..
28+ /// A wrapper around [`std::fs::File::open`] which includes the file path in the panic message.
29+ #[ track_caller]
30+ pub fn open_file < P : AsRef < Path > > ( path : P ) -> fs:: File {
31+ fs:: File :: open ( path. as_ref ( ) )
32+ . expect ( & format ! ( "the file in path \" {}\" could not be opened" , path. as_ref( ) . display( ) ) )
33+ }
34+
35+ /// A wrapper around [`std::fs::read`] which includes the file path in the panic message.
2936#[ track_caller]
3037pub fn read < P : AsRef < Path > > ( path : P ) -> Vec < u8 > {
3138 fs:: read ( path. as_ref ( ) )
3239 . expect ( & format ! ( "the file in path \" {}\" could not be read" , path. as_ref( ) . display( ) ) )
3340}
3441
35- /// A wrapper around [`std::fs::read_to_string`] which includes the file path in the panic message..
42+ /// A wrapper around [`std::fs::read_to_string`] which includes the file path in the panic message.
3643#[ track_caller]
3744pub fn read_to_string < P : AsRef < Path > > ( path : P ) -> String {
3845 fs:: read_to_string ( path. as_ref ( ) ) . expect ( & format ! (
@@ -41,14 +48,14 @@ pub fn read_to_string<P: AsRef<Path>>(path: P) -> String {
4148 ) )
4249}
4350
44- /// A wrapper around [`std::fs::read_dir`] which includes the file path in the panic message..
51+ /// A wrapper around [`std::fs::read_dir`] which includes the file path in the panic message.
4552#[ track_caller]
4653pub fn read_dir < P : AsRef < Path > > ( path : P ) -> fs:: ReadDir {
4754 fs:: read_dir ( path. as_ref ( ) )
4855 . expect ( & format ! ( "the directory in path \" {}\" could not be read" , path. as_ref( ) . display( ) ) )
4956}
5057
51- /// A wrapper around [`std::fs::write`] which includes the file path in the panic message..
58+ /// A wrapper around [`std::fs::write`] which includes the file path in the panic message.
5259#[ track_caller]
5360pub fn write < P : AsRef < Path > , C : AsRef < [ u8 ] > > ( path : P , contents : C ) {
5461 fs:: write ( path. as_ref ( ) , contents. as_ref ( ) ) . expect ( & format ! (
@@ -57,7 +64,7 @@ pub fn write<P: AsRef<Path>, C: AsRef<[u8]>>(path: P, contents: C) {
5764 ) ) ;
5865}
5966
60- /// A wrapper around [`std::fs::remove_dir_all`] which includes the file path in the panic message..
67+ /// A wrapper around [`std::fs::remove_dir_all`] which includes the file path in the panic message.
6168#[ track_caller]
6269pub fn remove_dir_all < P : AsRef < Path > > ( path : P ) {
6370 fs:: remove_dir_all ( path. as_ref ( ) ) . expect ( & format ! (
@@ -66,7 +73,7 @@ pub fn remove_dir_all<P: AsRef<Path>>(path: P) {
6673 ) ) ;
6774}
6875
69- /// A wrapper around [`std::fs::create_dir`] which includes the file path in the panic message..
76+ /// A wrapper around [`std::fs::create_dir`] which includes the file path in the panic message.
7077#[ track_caller]
7178pub fn create_dir < P : AsRef < Path > > ( path : P ) {
7279 fs:: create_dir ( path. as_ref ( ) ) . expect ( & format ! (
@@ -75,7 +82,7 @@ pub fn create_dir<P: AsRef<Path>>(path: P) {
7582 ) ) ;
7683}
7784
78- /// A wrapper around [`std::fs::create_dir_all`] which includes the file path in the panic message..
85+ /// A wrapper around [`std::fs::create_dir_all`] which includes the file path in the panic message.
7986#[ track_caller]
8087pub fn create_dir_all < P : AsRef < Path > > ( path : P ) {
8188 fs:: create_dir_all ( path. as_ref ( ) ) . expect ( & format ! (
@@ -84,7 +91,7 @@ pub fn create_dir_all<P: AsRef<Path>>(path: P) {
8491 ) ) ;
8592}
8693
87- /// A wrapper around [`std::fs::metadata`] which includes the file path in the panic message..
94+ /// A wrapper around [`std::fs::metadata`] which includes the file path in the panic message.
8895#[ track_caller]
8996pub fn metadata < P : AsRef < Path > > ( path : P ) -> fs:: Metadata {
9097 fs:: metadata ( path. as_ref ( ) ) . expect ( & format ! (
0 commit comments