implement section

This commit is contained in:
timeshifter
2023-01-06 14:14:21 +01:00
parent cb5c53c1c5
commit 0ed6359293
3 changed files with 69 additions and 12 deletions
+38
View File
@@ -0,0 +1,38 @@
use std::{collections::HashSet, hash::Hash};
use crate::Package;
#[derive(Debug, Eq)]
pub struct Section {
pub name: String,
pub packages: HashSet<Package>,
}
impl Section {
pub(crate) fn new(name: String, packages: HashSet<Package>) -> Self {
Self { name, packages }
}
pub fn from_lines<'a>(iter: &mut impl Iterator<Item = &'a str>) -> Self {
let name = iter.find(|line| line.starts_with('[')).unwrap().to_string();
let packages = iter
.take_while(|line| !line.starts_with('['))
.filter(|line| !line.contains(char::is_alphabetic))
.map(Package::from)
.collect();
Self::new(name, packages)
}
}
impl Hash for Section {
fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
self.name.hash(state);
}
}
impl PartialEq for Section {
fn eq(&self, other: &Self) -> bool {
self.name == other.name
}
}