Skip to content

Commit

Permalink
Drop optional vector, which can be just empty one
Browse files Browse the repository at this point in the history
  • Loading branch information
isbm committed Apr 5, 2024
1 parent 28f1bd0 commit e144464
Showing 1 changed file with 11 additions and 15 deletions.
26 changes: 11 additions & 15 deletions src/licences.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
pub mod cpritf;
pub mod debcpr;

/// Package License object, containing main license ID and possibly additional.
pub struct PkgLicence {
id: String,
other: Option<Vec<String>>,
other: Vec<String>,
}

impl PkgLicence {
/// Create new instance of PkgLicence object
pub fn new(id: String) -> Self {
PkgLicence { id, other: None }
PkgLicence { id, other: Vec::default() }
}

/// Returns the ID of the main license
Expand All @@ -16,23 +19,16 @@ impl PkgLicence {
}

/// Returns true if there are other licences then just the main ID
pub fn has_other(&self) -> bool {
return !self.get_other().is_empty();
}

/// Returns other licenses, if any
pub fn get_other(&self) -> Option<&Vec<String>> {
pub fn get_other(&self) -> &Vec<String> {
self.other.as_ref()
}

pub fn add(&mut self, other: String) {
if self.other.is_none() {
self.other = Some(Vec::default());
}

self.other = self
.other
.as_mut()
.map(|mut v| {
v.push(other);
v
})
.cloned();
self.other.push(other);
}
}

0 comments on commit e144464

Please sign in to comment.