@@ -7,24 +7,24 @@ use std::{fs, io};
77/// application, which are derived from the standard directories and the name
88/// of the project/organization.
99///
10- /// This corresponds to [`directories_next ::ProjectDirs`], except that the
10+ /// This corresponds to [`directories ::ProjectDirs`], except that the
1111/// functions create the directories if they don't exist, open them, and return
1212/// `Dir`s instead of returning `Path`s.
1313///
14- /// Unlike `directories_next ::ProjectDirs`, this API has no
14+ /// Unlike `directories ::ProjectDirs`, this API has no
1515/// `ProjectDirs::from_path`, `ProjectDirs::path` or
1616/// `ProjectDirs::project_path`, and the `*_dir` functions return `Dir`s rather
1717/// than `Path`s, because absolute paths don't interoperate well with the
1818/// capability model.
1919#[ derive( Clone ) ]
2020pub struct ProjectDirs {
21- inner : directories_next :: ProjectDirs ,
21+ inner : directories :: ProjectDirs ,
2222}
2323
2424impl ProjectDirs {
2525 /// Creates a `ProjectDirs` struct from values describing the project.
2626 ///
27- /// This corresponds to [`directories_next ::ProjectDirs::from`].
27+ /// This corresponds to [`directories ::ProjectDirs::from`].
2828 ///
2929 /// # Ambient Authority
3030 ///
@@ -37,13 +37,13 @@ impl ProjectDirs {
3737 ambient_authority : AmbientAuthority ,
3838 ) -> Option < Self > {
3939 let _ = ambient_authority;
40- let inner = directories_next :: ProjectDirs :: from ( qualifier, organization, application) ?;
40+ let inner = directories :: ProjectDirs :: from ( qualifier, organization, application) ?;
4141 Some ( Self { inner } )
4242 }
4343
4444 /// Returns the project's cache directory.
4545 ///
46- /// This corresponds to [`directories_next ::ProjectDirs::cache_dir`].
46+ /// This corresponds to [`directories ::ProjectDirs::cache_dir`].
4747 pub fn cache_dir ( & self ) -> io:: Result < Dir > {
4848 let path = self . inner . cache_dir ( ) ;
4949 fs:: create_dir_all ( path) ?;
@@ -52,7 +52,7 @@ impl ProjectDirs {
5252
5353 /// Returns the project's config directory.
5454 ///
55- /// This corresponds to [`directories_next ::ProjectDirs::config_dir`].
55+ /// This corresponds to [`directories ::ProjectDirs::config_dir`].
5656 pub fn config_dir ( & self ) -> io:: Result < Dir > {
5757 let path = self . inner . config_dir ( ) ;
5858 fs:: create_dir_all ( path) ?;
@@ -61,7 +61,7 @@ impl ProjectDirs {
6161
6262 /// Returns the project's data directory.
6363 ///
64- /// This corresponds to [`directories_next ::ProjectDirs::data_dir`].
64+ /// This corresponds to [`directories ::ProjectDirs::data_dir`].
6565 pub fn data_dir ( & self ) -> io:: Result < Dir > {
6666 let path = self . inner . data_dir ( ) ;
6767 fs:: create_dir_all ( path) ?;
@@ -70,7 +70,7 @@ impl ProjectDirs {
7070
7171 /// Returns the project's local data directory.
7272 ///
73- /// This corresponds to [`directories_next ::ProjectDirs::data_local_dir`].
73+ /// This corresponds to [`directories ::ProjectDirs::data_local_dir`].
7474 pub fn data_local_dir ( & self ) -> io:: Result < Dir > {
7575 let path = self . inner . data_local_dir ( ) ;
7676 fs:: create_dir_all ( path) ?;
@@ -79,10 +79,21 @@ impl ProjectDirs {
7979
8080 /// Returns the project's runtime directory.
8181 ///
82- /// This corresponds to [`directories_next ::ProjectDirs::runtime_dir`].
82+ /// This corresponds to [`directories ::ProjectDirs::runtime_dir`].
8383 pub fn runtime_dir ( & self ) -> io:: Result < Dir > {
8484 let path = self . inner . runtime_dir ( ) . ok_or_else ( not_found) ?;
8585 fs:: create_dir_all ( path) ?;
8686 Dir :: open_ambient_dir ( path, ambient_authority ( ) )
8787 }
88+
89+ /// Returns the project's state directory.
90+ ///
91+ /// This corresponds to [`directories::ProjectDirs::state_dir`].
92+ pub fn state_dir ( & self ) -> io:: Result < Option < Dir > > {
93+ let Some ( path) = self . inner . state_dir ( ) else {
94+ return Ok ( None ) ;
95+ } ;
96+ fs:: create_dir_all ( path) ?;
97+ Dir :: open_ambient_dir ( path, ambient_authority ( ) ) . map ( Some )
98+ }
8899}
0 commit comments