| 1 | use craterust-analyzer cargo cargo_toml 0.22.3 crate/::{Errorrust-analyzer cargo cargo_toml 0.22.3 error/Error#, Manifestrust-analyzer cargo cargo_toml 0.22.3 Manifest#, Valuerust-analyzer cargo toml 1.1.4+spec-1.1.0 value/Value#}; |
| 2 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::collectionsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/::HashSetrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/HashSet#; |
| 3 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::fsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/::read_dirrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/read_dir().; |
| 4 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/; |
| 5 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/::{Pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/Path#, PathBufrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/PathBuf#}; |
| 6 | |
| 7 | /// This crate supports reading `Cargo.toml` not only from a real directory, but also directly from other sources, like tarballs or bare git repos (BYO directory reader). |
| 8 | /// |
| 9 | /// The implementation must have a concept of the current directory, which is set to the crate's manifest dir. |
| 10 | pub trait AbstractFilesystemrust-analyzer cargo cargo_toml 0.22.3 afs/AbstractFilesystem# { |
| 11 | /// List all files and directories at the given relative path (no leading `/`). |
| 12 | fn file_names_inrust-analyzer cargo cargo_toml 0.22.3 afs/AbstractFilesystem#file_names_in().(&self, rel_path: &str) -> iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<HashSetrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/HashSet#<Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#<str>>>; |
| 13 | |
| 14 | /// `parse_root_workspace` is preferred. |
| 15 | /// |
| 16 | /// The `rel_path_hint` may be specified explicitly by `package.workspace` (it may be relative like `"../"`, without `Cargo.toml`) or `None`, |
| 17 | /// which means you have to search for workspace's `Cargo.toml` in parent directories. |
| 18 | /// |
| 19 | /// Read bytes of the root workspace manifest TOML file and return the path it's been read from. |
| 20 | /// The path needs to be an absolute path, because it will be used as the base path for inherited readmes, and would be ambiguous otherwise. |
| 21 | #[deprecated(note = "implement parse_root_workspace instead")] |
| 22 | #[doc(hidden)] |
| 23 | fn read_root_workspacerust-analyzer cargo cargo_toml 0.22.3 afs/AbstractFilesystem#read_root_workspace().(&self, _rel_path_hint: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<&Pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/Path#>) -> iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<(Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<u8>, PathBufrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/PathBuf#)> { |
| 24 | Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Errorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Error#::newrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/impl#[Error]new().(iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::ErrorKindrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/ErrorKind#::Unsupportedrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/ErrorKind#Unsupported#, "AbstractFilesystem::read_root_workspace unimplemented")) |
| 25 | } |
| 26 | |
| 27 | /// The `rel_path_hint` may be specified explicitly by `package.workspace` (it may be relative like `"../"`, without `Cargo.toml`) or `None`, |
| 28 | /// which means you have to search for workspace's `Cargo.toml` in parent directories. |
| 29 | /// |
| 30 | /// Read and parse the root workspace manifest TOML file and return the path it's been read from. |
| 31 | /// The path needs to be an absolute path, because it will be used as the base path for inherited readmes, and would be ambiguous otherwise. |
| 32 | #[allow(deprecated)] |
| 33 | fn parse_root_workspacerust-analyzer cargo cargo_toml 0.22.3 afs/AbstractFilesystem#parse_root_workspace().(&self, rel_path_hint: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<&Pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/Path#>) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(Manifestrust-analyzer cargo cargo_toml 0.22.3 Manifest#<Valuerust-analyzer cargo toml 1.1.4+spec-1.1.0 value/Value#>, PathBufrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/PathBuf#), Errorrust-analyzer cargo cargo_toml 0.22.3 error/Error#> { |
| 34 | let (data, path) = self.read_root_workspacerust-analyzer cargo cargo_toml 0.22.3 afs/AbstractFilesystem#read_root_workspace().(rel_path_hint).map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(|e| Errorrust-analyzer cargo cargo_toml 0.22.3 error/Error#::Workspacerust-analyzer cargo cargo_toml 0.22.3 error/Error#Workspace#(Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/impl#[`Box<T>`]new().((e.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(), rel_path_hint.maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]map().(PathBufrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/PathBuf#::fromrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[PathBuf][`From<&T>`]from().)))))?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 35 | let manifest = match Manifestrust-analyzer cargo cargo_toml 0.22.3 Manifest#::from_slicerust-analyzer cargo cargo_toml 0.22.3 impl#[Manifest]from_slice().(&data) { |
| 36 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(m) => m, |
| 37 | Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(e) => return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(Errorrust-analyzer cargo cargo_toml 0.22.3 error/Error#::Workspacerust-analyzer cargo cargo_toml 0.22.3 error/Error#Workspace#(Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/impl#[`Box<T>`]new().((e, Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(path))))), |
| 38 | }; |
| 39 | if manifest.workspacerust-analyzer cargo cargo_toml 0.22.3 Manifest#workspace..is_nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_none().() { |
| 40 | return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(Errorrust-analyzer cargo cargo_toml 0.22.3 error/Error#::Workspacerust-analyzer cargo cargo_toml 0.22.3 error/Error#Workspace#(Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/impl#[`Box<T>`]new().( |
| 41 | (Errorrust-analyzer cargo cargo_toml 0.22.3 error/Error#::WorkspaceIntegrityrust-analyzer cargo cargo_toml 0.22.3 error/Error#WorkspaceIntegrity#("Not a Workspace.\nUse package.workspace to select a differnt path, or implement cargo_toml::AbstractFilesystem::parse_root_workspace".intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().()), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(path)) |
| 42 | ))); |
| 43 | } |
| 44 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#((manifest, path)) |
| 45 | } |
| 46 | } |
| 47 | |
| 48 | impl<T> AbstractFilesystemrust-analyzer cargo cargo_toml 0.22.3 afs/AbstractFilesystem# for &T |
| 49 | where |
| 50 | T: AbstractFilesystemrust-analyzer cargo cargo_toml 0.22.3 afs/AbstractFilesystem# + ?Sizedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sized#, |
| 51 | { |
| 52 | fn file_names_inrust-analyzer cargo cargo_toml 0.22.3 afs/impl#[`&T`][AbstractFilesystem]file_names_in().(&self, rel_path: &str) -> iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<HashSetrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/HashSet#<Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#<str>>> { |
| 53 | <T as AbstractFilesystemrust-analyzer cargo cargo_toml 0.22.3 afs/AbstractFilesystem#>::file_names_inrust-analyzer cargo cargo_toml 0.22.3 afs/AbstractFilesystem#file_names_in().(*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().self, rel_path) |
| 54 | } |
| 55 | |
| 56 | #[allow(deprecated)] |
| 57 | fn read_root_workspacerust-analyzer cargo cargo_toml 0.22.3 afs/impl#[`&T`][AbstractFilesystem]read_root_workspace().(&self, rel_path_hint: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<&Pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/Path#>) -> iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<(Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<u8>, PathBufrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/PathBuf#)> { |
| 58 | <T as AbstractFilesystemrust-analyzer cargo cargo_toml 0.22.3 afs/AbstractFilesystem#>::read_root_workspacerust-analyzer cargo cargo_toml 0.22.3 afs/AbstractFilesystem#read_root_workspace().(*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().self, rel_path_hint) |
| 59 | } |
| 60 | |
| 61 | fn parse_root_workspacerust-analyzer cargo cargo_toml 0.22.3 afs/impl#[`&T`][AbstractFilesystem]parse_root_workspace().(&self, rel_path_hint: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<&Pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/Path#>) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(Manifestrust-analyzer cargo cargo_toml 0.22.3 Manifest#<Valuerust-analyzer cargo toml 1.1.4+spec-1.1.0 value/Value#>, PathBufrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/PathBuf#), Errorrust-analyzer cargo cargo_toml 0.22.3 error/Error#> { |
| 62 | <T as AbstractFilesystemrust-analyzer cargo cargo_toml 0.22.3 afs/AbstractFilesystem#>::parse_root_workspacerust-analyzer cargo cargo_toml 0.22.3 afs/AbstractFilesystem#parse_root_workspace().(*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().self, rel_path_hint) |
| 63 | } |
| 64 | } |
| 65 | |
| 66 | /// [`AbstractFilesystem`] implementation for real files. |
| 67 | pub struct Filesystemrust-analyzer cargo cargo_toml 0.22.3 afs/Filesystem#<'a> { |
| 68 | pathrust-analyzer cargo cargo_toml 0.22.3 afs/Filesystem#path.: &'a Pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/Path#, |
| 69 | } |
| 70 | |
| 71 | impl<'a> Filesystemrust-analyzer cargo cargo_toml 0.22.3 afs/Filesystem#<'a> { |
| 72 | #[must_use] |
| 73 | pub fn newrust-analyzer cargo cargo_toml 0.22.3 afs/impl#[`Filesystem<'a>`]new().(path: &'a Pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/Path#) -> Selfrust-analyzer cargo cargo_toml 0.22.3 afs/impl#[`Filesystem<'a>`] { |
| 74 | Selfrust-analyzer cargo cargo_toml 0.22.3 afs/impl#[`Filesystem<'a>`] { pathrust-analyzer cargo cargo_toml 0.22.3 afs/Filesystem#path. } |
| 75 | } |
| 76 | } |
| 77 | |
| 78 | impl AbstractFilesystemrust-analyzer cargo cargo_toml 0.22.3 afs/AbstractFilesystem# for Filesystemrust-analyzer cargo cargo_toml 0.22.3 afs/Filesystem#<'_> { |
| 79 | fn file_names_inrust-analyzer cargo cargo_toml 0.22.3 afs/impl#[`Filesystem<'_>`][AbstractFilesystem]file_names_in().(&self, rel_path: &str) -> iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<HashSetrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/HashSet#<Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#<str>>> { |
| 80 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(read_dirrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/read_dir().(self.pathrust-analyzer cargo cargo_toml 0.22.3 afs/Filesystem#path..joinrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]join().(rel_path))?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch(). |
| 81 | .filter_maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#filter_map().(|entry| entry.okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]ok().().maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]map().(|e| e.file_namerust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/impl#[DirEntry]file_name().().to_string_lossyrust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/os_str/impl#[OsStr]to_string_lossy().().into_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/impl#[`Cow<'_, B>`]into_owned().().intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().())) |
| 82 | .collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().()) |
| 83 | } |
| 84 | |
| 85 | fn parse_root_workspacerust-analyzer cargo cargo_toml 0.22.3 afs/impl#[`Filesystem<'_>`][AbstractFilesystem]parse_root_workspace().(&self, path: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<&Pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/Path#>) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(Manifestrust-analyzer cargo cargo_toml 0.22.3 Manifest#<Valuerust-analyzer cargo toml 1.1.4+spec-1.1.0 value/Value#>, PathBufrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/PathBuf#), Errorrust-analyzer cargo cargo_toml 0.22.3 error/Error#> { |
| 86 | match path { |
| 87 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(path) => { |
| 88 | let ws = self.pathrust-analyzer cargo cargo_toml 0.22.3 afs/Filesystem#path..joinrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]join().(path); |
| 89 | let toml_path = ws.joinrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]join().("Cargo.toml"); |
| 90 | let data = match stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::fsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/::readrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/read().(&toml_path) { |
| 91 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(d) => d, |
| 92 | Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(e) => return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(Errorrust-analyzer cargo cargo_toml 0.22.3 error/Error#::Workspacerust-analyzer cargo cargo_toml 0.22.3 error/Error#Workspace#(Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/impl#[`Box<T>`]new().((Errorrust-analyzer cargo cargo_toml 0.22.3 error/Error#::Iorust-analyzer cargo cargo_toml 0.22.3 error/Error#Io#(e), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(toml_path))))), |
| 93 | }; |
| 94 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#((parse_workspacerust-analyzer cargo cargo_toml 0.22.3 afs/parse_workspace().(&data, &toml_path)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch()., ws)) |
| 95 | }, |
| 96 | Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# => { |
| 97 | // Try relative path first |
| 98 | match find_workspacerust-analyzer cargo cargo_toml 0.22.3 afs/find_workspace().(self.pathrust-analyzer cargo cargo_toml 0.22.3 afs/Filesystem#path.) { |
| 99 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(found) => Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(found), |
| 100 | Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(err) if self.pathrust-analyzer cargo cargo_toml 0.22.3 afs/Filesystem#path..is_absoluterust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]is_absolute().() => Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(err), |
| 101 | Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(_) => find_workspacerust-analyzer cargo cargo_toml 0.22.3 afs/find_workspace().(&self.pathrust-analyzer cargo cargo_toml 0.22.3 afs/Filesystem#path..ancestorsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]ancestors().().lastrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#last().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().().canonicalizerust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]canonicalize().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().), |
| 102 | } |
| 103 | }, |
| 104 | } |
| 105 | } |
| 106 | } |
| 107 | |
| 108 | #[inline(never)] |
| 109 | fn find_workspacerust-analyzer cargo cargo_toml 0.22.3 afs/find_workspace().(path: &Pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/Path#) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(Manifestrust-analyzer cargo cargo_toml 0.22.3 Manifest#<Valuerust-analyzer cargo toml 1.1.4+spec-1.1.0 value/Value#>, PathBufrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/PathBuf#), Errorrust-analyzer cargo cargo_toml 0.22.3 error/Error#> { |
| 110 | if path.parentrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]parent().().is_nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_none().() { |
| 111 | return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Errorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Error#::newrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/impl#[Error]new().(iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::ErrorKindrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/ErrorKind#::NotFoundrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/ErrorKind#NotFound#, formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("Can't find workspace in '{}', because it has no parent directories", path.displayrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]display().())).intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().()) |
| 112 | } |
| 113 | let mut last_error = Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#; |
| 114 | path.ancestorsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]ancestors().().skiprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#skip().(1) |
| 115 | .maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(|parent| parent.joinrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]join().("Cargo.toml")) |
| 116 | .find_maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#find_map().(|p| { |
| 117 | let data = stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::fsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/::readrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/read().(&p).okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]ok().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][Try]branch().; |
| 118 | match parse_workspacerust-analyzer cargo cargo_toml 0.22.3 afs/parse_workspace().(&data, &p) { |
| 119 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(manifest) => Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#((manifest, p)), |
| 120 | Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(e) => { |
| 121 | last_error = Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(e); |
| 122 | Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# |
| 123 | }, |
| 124 | } |
| 125 | }) |
| 126 | .ok_orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]ok_or().(last_error.unwrap_or_elserust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap_or_else().(|| { |
| 127 | let has_slash = path.to_strrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]to_str().().is_some_andrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_some_and().(|s| s.ends_withrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]ends_with().('/')); |
| 128 | iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Errorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Error#::newrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/impl#[Error]new().(iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::ErrorKindrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/ErrorKind#::NotFoundrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/ErrorKind#NotFound#, formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("Can't find workspace in '{}{}..'", path.displayrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]display().(), if has_slash { "" } else { "/" })).intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().() |
| 129 | })) |
| 130 | } |
| 131 | |
| 132 | #[inline(never)] |
| 133 | fn parse_workspacerust-analyzer cargo cargo_toml 0.22.3 afs/parse_workspace().(data: &[u8], path: &Pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/Path#) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Manifestrust-analyzer cargo cargo_toml 0.22.3 Manifest#<Valuerust-analyzer cargo toml 1.1.4+spec-1.1.0 value/Value#>, Errorrust-analyzer cargo cargo_toml 0.22.3 error/Error#> { |
| 134 | let manifest = Manifestrust-analyzer cargo cargo_toml 0.22.3 Manifest#::from_slicerust-analyzer cargo cargo_toml 0.22.3 impl#[Manifest]from_slice().(data)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 135 | if manifest.workspacerust-analyzer cargo cargo_toml 0.22.3 Manifest#workspace..is_nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_none().() { |
| 136 | return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(Errorrust-analyzer cargo cargo_toml 0.22.3 error/Error#::WorkspaceIntegrityrust-analyzer cargo cargo_toml 0.22.3 error/Error#WorkspaceIntegrity#(formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("Manifest at {} was expected to be a workspace.", path.displayrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]display().()))); |
| 137 | } |
| 138 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(manifest) |
| 139 | } |