11use crate :: config:: Config ;
2- use crate :: error:: Error ;
2+ use crate :: error:: { Error , Result } ;
33use crate :: manifest:: Manifest ;
44use std:: ffi:: OsStr ;
55use std:: path:: { Path , PathBuf } ;
66
7- pub fn list_rust_files ( dir : & Path ) -> Result < Vec < String > , Error > {
7+ pub fn list_rust_files ( dir : & Path ) -> Result < Vec < String > > {
88 let mut files = Vec :: new ( ) ;
99 if dir. exists ( ) && dir. is_dir ( ) {
1010 let entries = std:: fs:: read_dir ( dir) . map_err ( |e| Error :: Io ( dir. to_owned ( ) , e) ) ?;
@@ -19,7 +19,7 @@ pub fn list_rust_files(dir: &Path) -> Result<Vec<String>, Error> {
1919 Ok ( files)
2020}
2121
22- fn member ( manifest : & Path , members : & [ String ] , package : & str ) -> Result < Option < PathBuf > , Error > {
22+ fn member ( manifest : & Path , members : & [ String ] , package : & str ) -> Result < Option < PathBuf > > {
2323 let workspace_dir = manifest. parent ( ) . unwrap ( ) ;
2424 for member in members {
2525 for manifest_dir in glob:: glob ( workspace_dir. join ( member) . to_str ( ) . unwrap ( ) ) ? {
@@ -35,7 +35,7 @@ fn member(manifest: &Path, members: &[String], package: &str) -> Result<Option<P
3535 Ok ( None )
3636}
3737
38- pub fn find_package ( path : & Path , name : Option < & str > ) -> Result < ( PathBuf , String ) , Error > {
38+ pub fn find_package ( path : & Path , name : Option < & str > ) -> Result < ( PathBuf , String ) > {
3939 let path = dunce:: canonicalize ( path) . map_err ( |e| Error :: Io ( path. to_owned ( ) , e) ) ?;
4040 for manifest_path in path
4141 . ancestors ( )
@@ -44,15 +44,17 @@ pub fn find_package(path: &Path, name: Option<&str>) -> Result<(PathBuf, String)
4444 {
4545 let manifest = Manifest :: parse_from_toml ( & manifest_path) ?;
4646 if let Some ( p) = manifest. package . as_ref ( ) {
47- if let ( Some ( n1 ) , n2 ) = ( name, & p . name ) {
48- if n1 == n2 {
47+ if let Some ( name ) = name {
48+ if name == p . name {
4949 return Ok ( ( manifest_path, p. name . clone ( ) ) ) ;
5050 }
5151 } else {
5252 return Ok ( ( manifest_path, p. name . clone ( ) ) ) ;
5353 }
5454 }
55- if let ( Some ( w) , Some ( name) ) = ( manifest. workspace . as_ref ( ) , name) {
55+ if let Some ( w) = manifest. workspace . as_ref ( ) {
56+ // TODO: This should also work if name is None - then all packages should simply be returned
57+ let name = name. ok_or ( Error :: MultiplePackagesNotSupported ) ?;
5658 if let Some ( manifest_path) = member ( & manifest_path, & w. members , name) ? {
5759 return Ok ( ( manifest_path, name. to_string ( ) ) ) ;
5860 }
@@ -61,7 +63,7 @@ pub fn find_package(path: &Path, name: Option<&str>) -> Result<(PathBuf, String)
6163 Err ( Error :: ManifestNotFound )
6264}
6365
64- pub fn find_workspace ( manifest : & Path , name : & str ) -> Result < Option < PathBuf > , Error > {
66+ pub fn find_workspace ( manifest : & Path , name : & str ) -> Result < Option < PathBuf > > {
6567 let dir = manifest. parent ( ) . unwrap ( ) ;
6668 for manifest_path in dir
6769 . ancestors ( )
@@ -81,7 +83,7 @@ pub fn find_workspace(manifest: &Path, name: &str) -> Result<Option<PathBuf>, Er
8183/// Returns the [`target-dir`] configured in `.cargo/config.toml` or `"target"` if not set.
8284///
8385/// [`target-dir`]: https://doc.rust-lang.org/cargo/reference/config.html#buildtarget-dir
84- pub fn get_target_dir_name ( config : Option < & Config > ) -> Result < String , Error > {
86+ pub fn get_target_dir_name ( config : Option < & Config > ) -> Result < String > {
8587 if let Some ( config) = config {
8688 if let Some ( build) = config. build . as_ref ( ) {
8789 if let Some ( target_dir) = & build. target_dir {
0 commit comments