Skip to content

Commit

Permalink
feat(choco): add ability to update metadata with global metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
AdmiringWorm committed Apr 10, 2021
1 parent b4b0bf2 commit 7196452
Show file tree
Hide file tree
Showing 7 changed files with 960 additions and 8 deletions.
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions aer_data/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ url = "2.2.1"
whoami = "1.1.2"

[dev-dependencies]
lazy_static = "1.4.0"
rand = "0.8.3"
rstest = "0.7.0"

[package.metadata.docs.rs]
Expand Down
11 changes: 11 additions & 0 deletions aer_data/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,17 @@ impl PackageData {
}
}

/// Implements a trait to use by updating necessary data
/// to a package specific handler.
pub trait DataUpdater<T> {
/// Updates the current data with the data in the specified from argument.
fn update_from<R: AsRef<T>>(&mut self, from: R);

/// Resets the current data by comparing it with the data in the specified
/// argument.
fn reset_same<R: AsRef<T>>(&mut self, from: R);
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down
13 changes: 9 additions & 4 deletions aer_data/src/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,10 @@ pub struct PackageMetadata {
impl PackageMetadata {
/// Creates a new instance of the package metadata with the specified
/// identifier.
pub fn new(id: &str) -> PackageMetadata {
pub fn new<T: AsRef<str>>(id: T) -> PackageMetadata {
PackageMetadata {
package_source_url: None,
id: id.to_owned(),
id: id.as_ref().to_string(),
maintainers: crate::defaults::maintainer(),
summary: String::new(),
project_url: crate::defaults::url(),
Expand Down Expand Up @@ -174,6 +174,11 @@ impl PackageMetadata {
&self.project_url
}

/// Wether the project source url has been set or not.
pub fn has_project_source_url(&self) -> bool {
self.project_source_url.is_some()
}

/// The location where the source of the software is hosted. Can be a
/// repository, or potentially a url to the location were source archives
/// can be downloaded (not a direct url).
Expand Down Expand Up @@ -223,8 +228,8 @@ impl PackageMetadata {
/// Allows setting the url to the project (usually the home page of the
/// software). Will return [url::ParseError] if the specified url is not
/// a url.
pub fn set_project_url(&mut self, url: &str) {
let url = Url::parse(url).unwrap(); // We want a failure here to abort the program
pub fn set_project_url<U: AsRef<str>>(&mut self, url: U) {
let url = Url::parse(url.as_ref()).unwrap(); // We want a failure here to abort the program
self.project_url = url;
}

Expand Down
Loading

0 comments on commit 7196452

Please sign in to comment.