Use ok_or_else

This commit is contained in:
notplants 2022-01-12 12:42:50 -05:00
parent 6c6413c1b4
commit 615431496b
2 changed files with 10 additions and 14 deletions

View File

@ -47,10 +47,10 @@ impl SsbMessageValue {
let msg_type = self
.content
.get("type")
.ok_or(GolgiError::ContentType("type field not found".to_string()))?;
let mtype_str: &str = msg_type.as_str().ok_or(GolgiError::ContentType(
"type field value is not a string as expected".to_string(),
))?;
.ok_or_else(|| GolgiError::ContentType("type field not found".to_string()))?;
let mtype_str: &str = msg_type.as_str().ok_or_else(|| {
GolgiError::ContentType("type field value is not a string as expected".to_string())
})?;
let enum_type = match mtype_str {
"about" => SsbMessageContentType::About,
"post" => SsbMessageContentType::Post,

View File

@ -3,7 +3,7 @@ use async_std::{
net::TcpStream,
stream::{Stream, StreamExt},
};
use futures::{pin_mut, TryStreamExt};
use futures::pin_mut;
use kuska_handshake::async_std::BoxStream;
use kuska_sodiumoxide::crypto::{auth, sign::ed25519};
@ -162,13 +162,9 @@ impl Sbot {
let id = result
.get("id")
.ok_or(GolgiError::Sbot(
"id key not found on whoami call".to_string(),
))?
.ok_or_else(|| GolgiError::Sbot("id key not found on whoami call".to_string()))?
.as_str()
.ok_or(GolgiError::Sbot(
"whoami returned non-string value".to_string(),
))?;
.ok_or_else(|| GolgiError::Sbot("whoami returned non-string value".to_string()))?;
Ok(id.to_string())
}
@ -292,9 +288,9 @@ impl Sbot {
Err(_) => false,
})
.await
.ok_or(GolgiError::Sbot(
"error while looking for about message with given key".to_string(),
))?;
.ok_or_else(|| {
GolgiError::Sbot("error while looking for about message with given key".to_string())
})?;
let latest_about_value = match latest_about_message {
Ok(msg) => {
msg