chore: parse API result into rust result
This commit is contained in:
parent
03a8470acb
commit
edae8f78ed
2 changed files with 11 additions and 1 deletions
2
Cargo.lock
generated
2
Cargo.lock
generated
|
@ -224,7 +224,7 @@ checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1"
|
|||
|
||||
[[package]]
|
||||
name = "forgejo-api-types"
|
||||
version = "0.1.6"
|
||||
version = "0.1.7"
|
||||
dependencies = [
|
||||
"chrono",
|
||||
"clap",
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue