From edae8f78ed3f38f28b2a44774ec09079537c92d4 Mon Sep 17 00:00:00 2001 From: RobWalt Date: Sat, 21 Oct 2023 21:54:58 +0200 Subject: [PATCH] chore: parse API result into rust result --- Cargo.lock | 2 +- src/types/api/search_results.rs | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index 2d8bb2c..627eb66 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -224,7 +224,7 @@ checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" [[package]] name = "forgejo-api-types" -version = "0.1.6" +version = "0.1.7" dependencies = [ "chrono", "clap", diff --git a/src/types/api/search_results.rs b/src/types/api/search_results.rs index 33084b8..9ec56c6 100644 --- a/src/types/api/search_results.rs +++ b/src/types/api/search_results.rs @@ -12,6 +12,16 @@ pub struct SearchResults { ok: IsOk, } +impl SearchResults { + /// converts the result data coming from the API into a rust native result + pub fn result(self) -> Result { + match self.ok { + IsOk::Yes => Ok(self.data), + IsOk::No => Err(self.data), + } + } +} + #[cfg(test)] mod search_results_tests { use crate::types::api::search_results::SearchResults;