@@ -19,32 +19,32 @@ pub fn list_rust_files(dir: &Path) -> Result<Vec<String>> {
1919 Ok ( files)
2020}
2121
22- fn match_package_name ( manifest : & Manifest , name : Option < & str > ) -> Option < String > {
22+ fn match_package_name ( manifest : & Manifest , name : Option < & str > ) -> bool {
2323 if let Some ( p) = & manifest. package {
2424 if let Some ( name) = name {
2525 if name == p. name {
26- return Some ( p . name . clone ( ) ) ;
26+ return true ;
2727 }
2828 } else {
29- return Some ( p . name . clone ( ) ) ;
29+ return true ;
3030 }
3131 }
3232
33- None
33+ false
3434}
3535
3636/// Tries to find a package by the given `name` in the [workspace root] or member
3737/// of the given [workspace] [`Manifest`].
3838///
39- /// When a workspace is not detected, call [`find_package ()`] instead.
39+ /// When a workspace is not detected, call [`find_package_manifest ()`] instead.
4040///
4141/// [workspace root]: https://doc.rust-lang.org/cargo/reference/workspaces.html#root-package
4242/// [workspace]: https://doc.rust-lang.org/cargo/reference/workspaces.html#workspaces
43- pub fn find_package_in_workspace (
43+ pub fn find_package_manifest_in_workspace (
4444 workspace_manifest_path : & Path ,
4545 workspace_manifest : & Manifest ,
4646 name : Option < & str > ,
47- ) -> Result < ( PathBuf , String ) > {
47+ ) -> Result < ( PathBuf , Manifest ) > {
4848 let workspace = workspace_manifest
4949 . workspace
5050 . as_ref ( )
@@ -57,8 +57,11 @@ pub fn find_package_in_workspace(
5757 let name = name. ok_or ( Error :: MultiplePackagesNotSupported ) ?;
5858
5959 // Check if the workspace manifest also contains a [package]
60- if let Some ( package) = match_package_name ( workspace_manifest, Some ( name) ) {
61- return Ok ( ( workspace_manifest_path. to_owned ( ) , package) ) ;
60+ if match_package_name ( workspace_manifest, Some ( name) ) {
61+ return Ok ( (
62+ workspace_manifest_path. to_owned ( ) ,
63+ workspace_manifest. clone ( ) ,
64+ ) ) ;
6265 }
6366
6467 // Check all member packages inside the workspace
@@ -73,8 +76,8 @@ pub fn find_package_in_workspace(
7376 return Err ( Error :: UnexpectedWorkspace ( manifest_path) ) ;
7477 }
7578
76- if let Some ( package ) = match_package_name ( & manifest, Some ( name) ) {
77- return Ok ( ( manifest_path, package ) ) ;
79+ if match_package_name ( & manifest, Some ( name) ) {
80+ return Ok ( ( manifest_path, manifest ) ) ;
7881 }
7982 }
8083 }
@@ -84,9 +87,9 @@ pub fn find_package_in_workspace(
8487
8588/// Recursively walk up the directories until finding a `Cargo.toml`
8689///
87- /// When a workspace has been detected, [`find_package_in_workspace ()`] to find packages
90+ /// When a workspace has been detected, [`find_package_manifest_in_workspace ()`] to find packages
8891/// instead (that are members of the given workspace).
89- pub fn find_package ( path : & Path , name : Option < & str > ) -> Result < ( PathBuf , String ) > {
92+ pub fn find_package_manifest ( path : & Path , name : Option < & str > ) -> Result < ( PathBuf , Manifest ) > {
9093 let path = dunce:: canonicalize ( path) . map_err ( |e| Error :: Io ( path. to_owned ( ) , e) ) ?;
9194 for manifest_path in path
9295 . ancestors ( )
@@ -100,8 +103,8 @@ pub fn find_package(path: &Path, name: Option<&str>) -> Result<(PathBuf, String)
100103 return Err ( Error :: UnexpectedWorkspace ( manifest_path) ) ;
101104 }
102105
103- if let Some ( package ) = match_package_name ( & manifest, name) {
104- return Ok ( ( manifest_path, package ) ) ;
106+ if match_package_name ( & manifest, name) {
107+ return Ok ( ( manifest_path, manifest ) ) ;
105108 }
106109 }
107110 Err ( Error :: ManifestNotFound )
0 commit comments