chore: parse API result into rust result

This commit is contained in:
RobWalt 2023-10-21 21:54:58 +02:00
parent 03a8470acb
commit edae8f78ed
No known key found for this signature in database
GPG key ID: 333C6AC0CEF0CE68
2 changed files with 11 additions and 1 deletions

2
Cargo.lock generated
View file

@ -224,7 +224,7 @@ checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1"
[[package]]
name = "forgejo-api-types"
version = "0.1.6"
version = "0.1.7"
dependencies = [
"chrono",
"clap",

View file

@ -12,6 +12,16 @@ pub struct SearchResults<T> {
ok: IsOk,
}
impl<T> SearchResults<T> {
/// converts the result data coming from the API into a rust native result
pub fn result(self) -> Result<T, T> {
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;