Struct cargo_edit::LocalManifest
source · pub struct LocalManifest {
pub path: PathBuf,
pub manifest: Manifest,
}Expand description
A Cargo manifest that is available locally.
Fields§
§path: PathBufPath to the manifest
manifest: ManifestManifest contents
Implementations§
source§impl LocalManifest
impl LocalManifest
sourcepub fn find(path: Option<&Path>) -> CargoResult<Self>
pub fn find(path: Option<&Path>) -> CargoResult<Self>
Construct a LocalManifest. If no path is provided, make an educated guess as to which one
the user means.
sourcepub fn try_new(path: &Path) -> CargoResult<Self>
pub fn try_new(path: &Path) -> CargoResult<Self>
Construct the LocalManifest corresponding to the Path provided.
sourcepub fn write(&self) -> CargoResult<()>
pub fn write(&self) -> CargoResult<()>
Write changes back to the file
sourcepub fn remove_from_table(
&mut self,
table_path: &[String],
name: &str
) -> CargoResult<()>
pub fn remove_from_table( &mut self, table_path: &[String], name: &str ) -> CargoResult<()>
Remove entry from a Cargo.toml.
Examples
use cargo_edit::{Dependency, LocalManifest, Manifest, RegistrySource};
use toml_edit;
let root = std::path::PathBuf::from("/").canonicalize().unwrap();
let path = root.join("Cargo.toml");
let manifest: toml_edit::Document = "
[dependencies]
cargo-edit = '0.1.0'
".parse().unwrap();
let mut manifest = LocalManifest { path, manifest: Manifest { data: manifest } };
assert!(manifest.remove_from_table(&["dependencies".to_owned()], "cargo-edit").is_ok());
assert!(manifest.remove_from_table(&["dependencies".to_owned()], "cargo-edit").is_err());
assert!(!manifest.data.contains_key("dependencies"));sourcepub fn get_dependency_tables_mut(
&mut self
) -> impl Iterator<Item = &mut dyn TableLike> + '_
pub fn get_dependency_tables_mut( &mut self ) -> impl Iterator<Item = &mut dyn TableLike> + '_
Allow mutating depedencies, wherever they live
sourcepub fn get_workspace_dependency_table_mut(
&mut self
) -> Option<&mut dyn TableLike>
pub fn get_workspace_dependency_table_mut( &mut self ) -> Option<&mut dyn TableLike>
Iterates mutably over the [workspace.dependencies].
sourcepub fn set_package_version(&mut self, version: &Version)
pub fn set_package_version(&mut self, version: &Version)
Override the manifest’s version
sourcepub fn version_is_inherited(&self) -> bool
pub fn version_is_inherited(&self) -> bool
true if the package inherits the workspace version
sourcepub fn get_workspace_version(&self) -> Option<Version>
pub fn get_workspace_version(&self) -> Option<Version>
Get the current workspace version, if any.
sourcepub fn set_workspace_version(&mut self, version: &Version)
pub fn set_workspace_version(&mut self, version: &Version)
Override the workspace’s version.