@@ -40,9 +40,16 @@ pub fn find_first_file_in_ancestors(dir_path: impl AsRef<Path>, filename: &str)
4040 None
4141}
4242
43+ #[ derive( Debug ) ]
44+ pub enum PackageTarget {
45+ Bin { crate_name : String } ,
46+ Lib ,
47+ }
48+
4349#[ derive( PartialEq , Eq , Debug ) ]
4450pub struct Project {
4551 package_name : PackageName ,
52+ manifest_path : PathBuf ,
4653 readme_path : Option < PathBuf > ,
4754 lib_path : Option < PathBuf > ,
4855 bin_path : HashMap < String , PathBuf > ,
@@ -114,16 +121,16 @@ impl Project {
114121 let bin_packages =
115122 package. targets . iter ( ) . filter ( |target| target. kind . contains ( & TargetKind :: Bin ) ) ;
116123
117- let directory = package
118- . manifest_path
119- . clone ( )
120- . into_std_path_buf ( )
124+ let manifest_path = package. manifest_path . clone ( ) . into_std_path_buf ( ) ;
125+
126+ let directory = manifest_path
121127 . parent ( )
122128 . expect ( "error getting the parent path of the manifest file" )
123129 . to_path_buf ( ) ;
124130
125131 Project {
126132 package_name : package. name . clone ( ) ,
133+ manifest_path,
127134 readme_path : package. readme . as_ref ( ) . map ( |p| p. clone ( ) . into_std_path_buf ( ) ) ,
128135 lib_path : lib_package. map ( |t| t. src_path . clone ( ) . into_std_path_buf ( ) ) ,
129136 bin_path : bin_packages
@@ -138,6 +145,14 @@ impl Project {
138145 self . lib_path . as_ref ( ) . filter ( |p| p. is_file ( ) ) . map ( PathBuf :: as_path)
139146 }
140147
148+ #[ must_use]
149+ pub fn get_bin_default_crate_name ( & self ) -> Option < & str > {
150+ match self . bin_path . len ( ) {
151+ 1 => self . bin_path . keys ( ) . next ( ) . map ( String :: as_str) ,
152+ _ => None ,
153+ }
154+ }
155+
141156 #[ must_use]
142157 pub fn get_bin_default_entryfile_path ( & self ) -> Option < & Path > {
143158 match self . bin_path . len ( ) {
@@ -168,15 +183,11 @@ impl Project {
168183 pub fn get_package_name ( & self ) -> & PackageName {
169184 & self . package_name
170185 }
171- }
172186
173- fn project_package_name ( manifest_path : impl AsRef < Path > ) -> Option < String > {
174- let str: String = std:: fs:: read_to_string ( & manifest_path) . ok ( ) ?;
175- let toml: toml:: Value = toml:: from_str ( & str) . ok ( ) ?;
176- let package_name =
177- toml. get ( "package" ) . and_then ( |v| v. get ( "name" ) ) . and_then ( toml:: Value :: as_str) ?;
178-
179- Some ( package_name. to_owned ( ) )
187+ #[ must_use]
188+ pub fn get_manifest_path ( & self ) -> & PathBuf {
189+ & self . manifest_path
190+ }
180191}
181192
182193#[ derive( Eq , PartialEq , Clone , Debug ) ]
0 commit comments