From adfdd7b2460f12336888f284647c84423361fe2d Mon Sep 17 00:00:00 2001 From: eatradish Date: Mon, 6 May 2024 00:21:36 +0800 Subject: [PATCH] refactor(oma-refresh): use `TryFrom` trait for `SourceEntry` convert to `OmaSourceEntry` --- oma-refresh/src/db.rs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/oma-refresh/src/db.rs b/oma-refresh/src/db.rs index 57d1b8e4..7398e134 100644 --- a/oma-refresh/src/db.rs +++ b/oma-refresh/src/db.rs @@ -163,13 +163,13 @@ pub fn get_sources>(sysroot: P) -> Result> { 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)?); } } } @@ -200,8 +200,10 @@ pub enum Event { Info(String), } -impl OmaSourceEntry { - fn new(v: &SourceEntry) -> Result { +impl TryFrom<&SourceEntry> for OmaSourceEntry { + type Error = RefreshError; + + fn try_from(v: &SourceEntry) -> std::prelude::v1::Result { let from = if v.url().starts_with("http://") || v.url().starts_with("https://") { OmaSourceEntryFrom::Http } else if v.url().starts_with("file://") {