Struct cargo_edit::LocalManifest
source · [−]Expand description
A Cargo manifest that is available locally.
Fields
path: PathBuf
Path to the manifest
manifest: Manifest
Manifest contents
Implementations
sourceimpl 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 upgrade(
&mut self,
dependency: &Dependency,
dry_run: bool,
skip_compatible: bool
) -> CargoResult<()>
pub fn upgrade(
&mut self,
dependency: &Dependency,
dry_run: bool,
skip_compatible: bool
) -> CargoResult<()>
Instruct this manifest to upgrade a single dependency. If this manifest does not have that dependency, it does nothing.
sourcepub fn get_dependency(
&self,
table_path: &[String],
dep_key: &str
) -> CargoResult<Dependency>
pub fn get_dependency(
&self,
table_path: &[String],
dep_key: &str
) -> CargoResult<Dependency>
Lookup a dependency
sourcepub fn get_dependencies(
&self
) -> impl Iterator<Item = (Vec<String>, CargoResult<Dependency>)> + '_
pub fn get_dependencies(
&self
) -> impl Iterator<Item = (Vec<String>, CargoResult<Dependency>)> + '_
Returns all dependencies
sourcepub fn get_dependency_versions<'s>(
&'s self,
dep_key: &'s str
) -> impl Iterator<Item = (Vec<String>, CargoResult<Dependency>)> + 's
pub fn get_dependency_versions<'s>(
&'s self,
dep_key: &'s str
) -> impl Iterator<Item = (Vec<String>, CargoResult<Dependency>)> + 's
Lookup a dependency
sourcepub fn insert_into_table(
&mut self,
table_path: &[String],
dep: &Dependency
) -> CargoResult<()>
pub fn insert_into_table(
&mut self,
table_path: &[String],
dep: &Dependency
) -> CargoResult<()>
Add entry to a Cargo.toml.
sourcepub fn update_table_entry(
&mut self,
table_path: &[String],
dep: &Dependency,
dry_run: bool
) -> CargoResult<()>
pub fn update_table_entry(
&mut self,
table_path: &[String],
dep: &Dependency,
dry_run: bool
) -> CargoResult<()>
Update an entry in Cargo.toml.
sourcepub fn update_table_named_entry(
&mut self,
table_path: &[String],
dep_key: &str,
dep: &Dependency,
dry_run: bool
) -> CargoResult<()>
pub fn update_table_named_entry(
&mut self,
table_path: &[String],
dep_key: &str,
dep: &Dependency,
dry_run: bool
) -> CargoResult<()>
Update an entry with a specified name in Cargo.toml.
sourcepub fn remove_from_table(&mut self, table: &str, name: &str) -> CargoResult<()>
pub fn remove_from_table(&mut self, table: &str, name: &str) -> CargoResult<()>
Remove entry from a Cargo.toml.
Examples
use cargo_edit::{Dependency, LocalManifest, Manifest};
use toml_edit;
let root = std::path::PathBuf::from("/").canonicalize().unwrap();
let path = root.join("Cargo.toml");
let mut manifest = LocalManifest { path, manifest: Manifest { data: toml_edit::Document::new() } };
let dep = Dependency::new("cargo-edit").set_version("0.1.0");
let _ = manifest.insert_into_table(&vec!["dependencies".to_owned()], &dep);
assert!(manifest.remove_from_table("dependencies", &dep.name).is_ok());
assert!(manifest.remove_from_table("dependencies", &dep.name).is_err());
assert!(!manifest.data.contains_key("dependencies"));
sourcepub fn add_deps(
&mut self,
table: &[String],
deps: &[Dependency]
) -> CargoResult<()>
pub fn add_deps(
&mut self,
table: &[String],
deps: &[Dependency]
) -> CargoResult<()>
Add multiple dependencies to manifest
sourcepub fn get_dependency_tables_mut<'r>(
&'r mut self
) -> impl Iterator<Item = &mut dyn TableLike> + 'r
pub fn get_dependency_tables_mut<'r>(
&'r mut self
) -> impl Iterator<Item = &mut dyn TableLike> + 'r
Allow mutating depedencies, wherever they live
sourcepub fn set_package_version(&mut self, version: &Version)
pub fn set_package_version(&mut self, version: &Version)
Override the manifest’s version
Methods from Deref<Target = Manifest>
sourcepub fn package_name(&self) -> CargoResult<&str>
pub fn package_name(&self) -> CargoResult<&str>
Get the manifest’s package name
sourcepub fn get_table<'a>(&'a self, table_path: &[String]) -> CargoResult<&'a Item>
pub fn get_table<'a>(&'a self, table_path: &[String]) -> CargoResult<&'a Item>
Get the specified table from the manifest.
sourcepub fn get_table_mut<'a>(
&'a mut self,
table_path: &[String]
) -> CargoResult<&'a mut Item>
pub fn get_table_mut<'a>(
&'a mut self,
table_path: &[String]
) -> CargoResult<&'a mut Item>
Get the specified table from the manifest.
Trait Implementations
sourceimpl Debug for LocalManifest
impl Debug for LocalManifest
sourceimpl Deref for LocalManifest
impl Deref for LocalManifest
Auto Trait Implementations
impl RefUnwindSafe for LocalManifest
impl Send for LocalManifest
impl Sync for LocalManifest
impl Unpin for LocalManifest
impl UnwindSafe for LocalManifest
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more