Skip to content

Commit

Permalink
refactor(oma-refresh): use TryFrom trait for SourceEntry convert …
Browse files Browse the repository at this point in the history
…to `OmaSourceEntry`
  • Loading branch information
eatradish committed May 5, 2024
1 parent 87c9741 commit adfdd7b
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions oma-refresh/src/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,13 +163,13 @@ pub fn get_sources<P: AsRef<Path>>(sysroot: P) -> Result<Vec<OmaSourceEntry>> {
SourceListType::SourceLine(ref lines) => {
for i in lines {
if let SourceLine::Entry(entry) = i {
res.push(OmaSourceEntry::new(entry)?);
res.push(OmaSourceEntry::try_from(entry)?);
}
}
}
SourceListType::Deb822(ref e) => {
for i in &e.entries {
res.push(OmaSourceEntry::new(i)?);
res.push(OmaSourceEntry::try_from(i)?);
}
}
}
Expand Down Expand Up @@ -200,8 +200,10 @@ pub enum Event {
Info(String),
}

impl OmaSourceEntry {
fn new(v: &SourceEntry) -> Result<Self> {
impl TryFrom<&SourceEntry> for OmaSourceEntry {
type Error = RefreshError;

fn try_from(v: &SourceEntry) -> std::prelude::v1::Result<Self, Self::Error> {
let from = if v.url().starts_with("http://") || v.url().starts_with("https://") {
OmaSourceEntryFrom::Http
} else if v.url().starts_with("file://") {
Expand Down

0 comments on commit adfdd7b

Please sign in to comment.