Skip to content

Commit

Permalink
refactor: move getters method together
Browse files Browse the repository at this point in the history
  • Loading branch information
weihanglo committed Jun 28, 2023
1 parent d99fed2 commit e313b61
Showing 1 changed file with 20 additions and 20 deletions.
40 changes: 20 additions & 20 deletions src/cargo/util/toml/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1632,18 +1632,6 @@ impl InheritableFields {
("package.version", version -> semver::Version),
}

pub fn update_deps(&mut self, deps: Option<BTreeMap<String, TomlDependency>>) {
self.dependencies = deps;
}

pub fn update_lints(&mut self, lints: Option<TomlLints>) {
self.lints = lints;
}

pub fn update_ws_path(&mut self, ws_root: PathBuf) {
self.ws_root = ws_root;
}

/// Gets a workspace dependency with the `name`.
pub fn get_dependency(&self, name: &str, package_root: &Path) -> CargoResult<TomlDependency> {
let Some(deps) = &self.dependencies else {
Expand All @@ -1659,6 +1647,14 @@ impl InheritableFields {
Ok(dep)
}

/// Gets the field `workspace.package.license-file`.
pub fn license_file(&self, package_root: &Path) -> CargoResult<String> {
let Some(license_file) = &self.license_file else {
bail!("`workspace.package.license-file` was not defined");
};
resolve_relative_path("license-file", &self.ws_root, package_root, license_file)
}

/// Gets the field `workspace.package.readme`.
pub fn readme(&self, package_root: &Path) -> CargoResult<StringOrBool> {
let Some(readme) = readme_for_package(self.ws_root.as_path(), self.readme.as_ref()) else {
Expand All @@ -1668,17 +1664,21 @@ impl InheritableFields {
.map(StringOrBool::String)
}

/// Gets the field `workspace.package.license-file`.
pub fn license_file(&self, package_root: &Path) -> CargoResult<String> {
let Some(license_file) = &self.license_file else {
bail!("`workspace.package.license-file` was not defined");
};
resolve_relative_path("license-file", &self.ws_root, package_root, license_file)
}

pub fn ws_root(&self) -> &PathBuf {
&self.ws_root
}

pub fn update_deps(&mut self, deps: Option<BTreeMap<String, TomlDependency>>) {
self.dependencies = deps;
}

pub fn update_lints(&mut self, lints: Option<TomlLints>) {
self.lints = lints;
}

pub fn update_ws_path(&mut self, ws_root: PathBuf) {
self.ws_root = ws_root;
}
}

impl TomlPackage {
Expand Down

0 comments on commit e313b61

Please sign in to comment.