diff --git a/crates/bevy_macro_utils/src/bevy_manifest.rs b/crates/bevy_macro_utils/src/bevy_manifest.rs index 813f8533c9..b0d321ba22 100644 --- a/crates/bevy_macro_utils/src/bevy_manifest.rs +++ b/crates/bevy_macro_utils/src/bevy_manifest.rs @@ -8,12 +8,12 @@ use std::{ path::{Path, PathBuf}, time::SystemTime, }; -use toml_edit::{DocumentMut, Item}; +use toml_edit::{ImDocument, Item}; /// The path to the `Cargo.toml` file for the Bevy project. #[derive(Debug)] pub struct BevyManifest { - manifest: DocumentMut, + manifest: ImDocument>, modified_time: SystemTime, } @@ -34,14 +34,15 @@ impl BevyManifest { return manifest; } } + + let manifest = BevyManifest { + manifest: Self::read_manifest(&manifest_path), + modified_time, + }; + + let key = manifest_path.clone(); let mut manifests = MANIFESTS.write(); - manifests.insert( - manifest_path.clone(), - BevyManifest { - manifest: Self::read_manifest(&manifest_path), - modified_time, - }, - ); + manifests.insert(key, manifest); RwLockReadGuard::map(RwLockWriteGuard::downgrade(manifests), |manifests| { manifests.get(&manifest_path).unwrap() @@ -69,11 +70,11 @@ impl BevyManifest { std::fs::metadata(cargo_manifest_path).and_then(|metadata| metadata.modified()) } - fn read_manifest(path: &Path) -> DocumentMut { + fn read_manifest(path: &Path) -> ImDocument> { let manifest = std::fs::read_to_string(path) - .unwrap_or_else(|_| panic!("Unable to read cargo manifest: {}", path.display())); - manifest - .parse::() + .unwrap_or_else(|_| panic!("Unable to read cargo manifest: {}", path.display())) + .into_boxed_str(); + ImDocument::parse(manifest) .unwrap_or_else(|_| panic!("Failed to parse cargo manifest: {}", path.display())) }