@@ -47,9 +47,16 @@ pub fn find_first_file_in_ancestors(dir_path: impl AsRef<Path>, filename: &str)
4747 None
4848}
4949
50+ #[ derive( Debug ) ]
51+ pub enum PackageTarget {
52+ Bin { crate_name : String } ,
53+ Lib ,
54+ }
55+
5056#[ derive( PartialEq , Eq , Debug ) ]
5157pub struct Project {
5258 package_name : String ,
59+ manifest_path : PathBuf ,
5360 readme_path : Option < PathBuf > ,
5461 lib_path : Option < PathBuf > ,
5562 bin_path : HashMap < String , PathBuf > ,
@@ -110,16 +117,16 @@ impl Project {
110117 let bin_packages =
111118 package. targets . iter ( ) . filter ( |target| target. kind . contains ( & TargetKind :: Bin ) ) ;
112119
113- let directory = package
114- . manifest_path
115- . clone ( )
116- . into_std_path_buf ( )
120+ let manifest_path = package. manifest_path . clone ( ) . into_std_path_buf ( ) ;
121+
122+ let directory = manifest_path
117123 . parent ( )
118124 . expect ( "error getting the parent path of the manifest file" )
119125 . to_path_buf ( ) ;
120126
121127 Project {
122128 package_name : package. name . clone ( ) ,
129+ manifest_path,
123130 readme_path : package. readme . as_ref ( ) . map ( |p| p. clone ( ) . into_std_path_buf ( ) ) ,
124131 lib_path : lib_package. map ( |t| t. src_path . clone ( ) . into_std_path_buf ( ) ) ,
125132 bin_path : bin_packages
@@ -134,6 +141,14 @@ impl Project {
134141 self . lib_path . as_ref ( ) . filter ( |p| p. is_file ( ) ) . map ( PathBuf :: as_path)
135142 }
136143
144+ #[ must_use]
145+ pub fn get_bin_default_crate_name ( & self ) -> Option < & str > {
146+ match self . bin_path . len ( ) {
147+ 1 => self . bin_path . keys ( ) . next ( ) . map ( String :: as_str) ,
148+ _ => None ,
149+ }
150+ }
151+
137152 #[ must_use]
138153 pub fn get_bin_default_entryfile_path ( & self ) -> Option < & Path > {
139154 match self . bin_path . len ( ) {
@@ -164,15 +179,11 @@ impl Project {
164179 pub fn get_package_name ( & self ) -> & str {
165180 & self . package_name
166181 }
167- }
168182
169- fn project_package_name ( manifest_path : impl AsRef < Path > ) -> Option < String > {
170- let str: String = std:: fs:: read_to_string ( & manifest_path) . ok ( ) ?;
171- let toml: toml:: Value = toml:: from_str ( & str) . ok ( ) ?;
172- let package_name =
173- toml. get ( "package" ) . and_then ( |v| v. get ( "name" ) ) . and_then ( toml:: Value :: as_str) ?;
174-
175- Some ( package_name. to_owned ( ) )
183+ #[ must_use]
184+ pub fn get_manifest_path ( & self ) -> & PathBuf {
185+ & self . manifest_path
186+ }
176187}
177188
178189#[ derive( Eq , PartialEq , Clone , Debug ) ]
0 commit comments