Skip to content

Commit

Permalink
Replace ok_or with ok_or_else (surrealdb#4573)
Browse files Browse the repository at this point in the history
  • Loading branch information
gsserge authored Aug 21, 2024
1 parent bc6ad3a commit f795434
Showing 1 changed file with 38 additions and 35 deletions.
73 changes: 38 additions & 35 deletions core/src/kvs/tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -790,7 +790,7 @@ impl Transaction {
Ok(match res {
Ok(val) => val,
Err(cache) => {
let val = self.get(key, None).await?.ok_or(Error::NdNotFound {
let val = self.get(key, None).await?.ok_or_else(|| Error::NdNotFound {
value: id.to_string(),
})?;
let val: Node = val.into();
Expand All @@ -810,7 +810,7 @@ impl Transaction {
Ok(match res {
Ok(val) => val,
Err(cache) => {
let val = self.get(key, None).await?.ok_or(Error::UserRootNotFound {
let val = self.get(key, None).await?.ok_or_else(|| Error::UserRootNotFound {
value: us.to_owned(),
})?;
let val: DefineUserStatement = val.into();
Expand All @@ -830,7 +830,7 @@ impl Transaction {
Ok(match res {
Ok(val) => val,
Err(cache) => {
let val = self.get(key, None).await?.ok_or(Error::AccessRootNotFound {
let val = self.get(key, None).await?.ok_or_else(|| Error::AccessRootNotFound {
ac: ra.to_owned(),
})?;
let val: DefineAccessStatement = val.into();
Expand All @@ -854,10 +854,11 @@ impl Transaction {
Ok(match res {
Ok(val) => val,
Err(cache) => {
let val = self.get(key, None).await?.ok_or(Error::AccessGrantRootNotFound {
ac: ac.to_owned(),
gr: gr.to_owned(),
})?;
let val =
self.get(key, None).await?.ok_or_else(|| Error::AccessGrantRootNotFound {
ac: ac.to_owned(),
gr: gr.to_owned(),
})?;
let val: AccessGrant = val.into();
let val = Entry::Any(Arc::new(val));
let _ = cache.insert(val.clone());
Expand All @@ -875,7 +876,7 @@ impl Transaction {
Ok(match res {
Ok(val) => val,
Err(cache) => {
let val = self.get(key, None).await?.ok_or(Error::NsNotFound {
let val = self.get(key, None).await?.ok_or_else(|| Error::NsNotFound {
value: ns.to_owned(),
})?;
let val: DefineNamespaceStatement = val.into();
Expand All @@ -895,7 +896,7 @@ impl Transaction {
Ok(match res {
Ok(val) => val,
Err(cache) => {
let val = self.get(key, None).await?.ok_or(Error::UserNsNotFound {
let val = self.get(key, None).await?.ok_or_else(|| Error::UserNsNotFound {
value: us.to_owned(),
ns: ns.to_owned(),
})?;
Expand All @@ -920,7 +921,7 @@ impl Transaction {
Ok(match res {
Ok(val) => val,
Err(cache) => {
let val = self.get(key, None).await?.ok_or(Error::AccessNsNotFound {
let val = self.get(key, None).await?.ok_or_else(|| Error::AccessNsNotFound {
ac: na.to_owned(),
ns: ns.to_owned(),
})?;
Expand All @@ -946,11 +947,12 @@ impl Transaction {
Ok(match res {
Ok(val) => val,
Err(cache) => {
let val = self.get(key, None).await?.ok_or(Error::AccessGrantNsNotFound {
ac: ac.to_owned(),
gr: gr.to_owned(),
ns: ns.to_owned(),
})?;
let val =
self.get(key, None).await?.ok_or_else(|| Error::AccessGrantNsNotFound {
ac: ac.to_owned(),
gr: gr.to_owned(),
ns: ns.to_owned(),
})?;
let val: AccessGrant = val.into();
let val = Entry::Any(Arc::new(val));
let _ = cache.insert(val.clone());
Expand All @@ -968,7 +970,7 @@ impl Transaction {
Ok(match res {
Ok(val) => val,
Err(cache) => {
let val = self.get(key, None).await?.ok_or(Error::DbNotFound {
let val = self.get(key, None).await?.ok_or_else(|| Error::DbNotFound {
value: db.to_owned(),
})?;
let val: DefineDatabaseStatement = val.into();
Expand All @@ -993,7 +995,7 @@ impl Transaction {
Ok(match res {
Ok(val) => val,
Err(cache) => {
let val = self.get(key, None).await?.ok_or(Error::UserDbNotFound {
let val = self.get(key, None).await?.ok_or_else(|| Error::UserDbNotFound {
value: us.to_owned(),
ns: ns.to_owned(),
db: db.to_owned(),
Expand All @@ -1020,7 +1022,7 @@ impl Transaction {
Ok(match res {
Ok(val) => val,
Err(cache) => {
let val = self.get(key, None).await?.ok_or(Error::AccessDbNotFound {
let val = self.get(key, None).await?.ok_or_else(|| Error::AccessDbNotFound {
ac: da.to_owned(),
ns: ns.to_owned(),
db: db.to_owned(),
Expand Down Expand Up @@ -1048,12 +1050,13 @@ impl Transaction {
Ok(match res {
Ok(val) => val,
Err(cache) => {
let val = self.get(key, None).await?.ok_or(Error::AccessGrantDbNotFound {
ac: ac.to_owned(),
gr: gr.to_owned(),
ns: ns.to_owned(),
db: db.to_owned(),
})?;
let val =
self.get(key, None).await?.ok_or_else(|| Error::AccessGrantDbNotFound {
ac: ac.to_owned(),
gr: gr.to_owned(),
ns: ns.to_owned(),
db: db.to_owned(),
})?;
let val: AccessGrant = val.into();
let val = Entry::Any(Arc::new(val));
let _ = cache.insert(val.clone());
Expand All @@ -1077,7 +1080,7 @@ impl Transaction {
Ok(match res {
Ok(val) => val,
Err(cache) => {
let val = self.get(key, None).await?.ok_or(Error::MlNotFound {
let val = self.get(key, None).await?.ok_or_else(|| Error::MlNotFound {
value: format!("{ml}<{vn}>"),
})?;
let val: DefineModelStatement = val.into();
Expand All @@ -1102,7 +1105,7 @@ impl Transaction {
Ok(match res {
Ok(val) => val,
Err(cache) => {
let val = self.get(key, None).await?.ok_or(Error::AzNotFound {
let val = self.get(key, None).await?.ok_or_else(|| Error::AzNotFound {
value: az.to_owned(),
})?;
let val: DefineAnalyzerStatement = val.into();
Expand All @@ -1127,7 +1130,7 @@ impl Transaction {
Ok(match res {
Ok(val) => val,
Err(cache) => {
let val = self.get(key, None).await?.ok_or(Error::FcNotFound {
let val = self.get(key, None).await?.ok_or_else(|| Error::FcNotFound {
value: fc.to_owned(),
})?;
let val: DefineFunctionStatement = val.into();
Expand All @@ -1152,7 +1155,7 @@ impl Transaction {
Ok(match res {
Ok(val) => val,
Err(cache) => {
let val = self.get(key, None).await?.ok_or(Error::PaNotFound {
let val = self.get(key, None).await?.ok_or_else(|| Error::PaNotFound {
value: pa.to_owned(),
})?;
let val: DefineParamStatement = val.into();
Expand All @@ -1177,7 +1180,7 @@ impl Transaction {
Ok(match res {
Ok(val) => val,
Err(cache) => {
let val = self.get(key, None).await?.ok_or(Error::TbNotFound {
let val = self.get(key, None).await?.ok_or_else(|| Error::TbNotFound {
value: tb.to_owned(),
})?;
let val: DefineTableStatement = val.into();
Expand All @@ -1203,7 +1206,7 @@ impl Transaction {
Ok(match res {
Ok(val) => val,
Err(cache) => {
let val = self.get(key, None).await?.ok_or(Error::EvNotFound {
let val = self.get(key, None).await?.ok_or_else(|| Error::EvNotFound {
value: ev.to_owned(),
})?;
let val: DefineEventStatement = val.into();
Expand All @@ -1229,7 +1232,7 @@ impl Transaction {
Ok(match res {
Ok(val) => val,
Err(cache) => {
let val = self.get(key, None).await?.ok_or(Error::FdNotFound {
let val = self.get(key, None).await?.ok_or_else(|| Error::FdNotFound {
value: fd.to_owned(),
})?;
let val: DefineFieldStatement = val.into();
Expand All @@ -1255,7 +1258,7 @@ impl Transaction {
Ok(match res {
Ok(val) => val,
Err(cache) => {
let val = self.get(key, None).await?.ok_or(Error::IxNotFound {
let val = self.get(key, None).await?.ok_or_else(|| Error::IxNotFound {
value: ix.to_owned(),
})?;
let val: DefineIndexStatement = val.into();
Expand Down Expand Up @@ -1445,7 +1448,7 @@ impl Transaction {
// The entry is not in the cache
Err(cache) => {
// Try to fetch the value from the datastore
let res = self.get(&key, None).await?.ok_or(Error::NsNotFound {
let res = self.get(&key, None).await?.ok_or_else(|| Error::NsNotFound {
value: ns.to_owned(),
});
// Check whether the value exists in the datastore
Expand Down Expand Up @@ -1498,7 +1501,7 @@ impl Transaction {
// The entry is not in the cache
Err(cache) => {
// Try to fetch the value from the datastore
let res = self.get(&key, None).await?.ok_or(Error::DbNotFound {
let res = self.get(&key, None).await?.ok_or_else(|| Error::DbNotFound {
value: db.to_owned(),
});
// Check whether the value exists in the datastore
Expand Down Expand Up @@ -1566,7 +1569,7 @@ impl Transaction {
// The entry is not in the cache
Err(cache) => {
// Try to fetch the value from the datastore
let res = self.get(&key, None).await?.ok_or(Error::TbNotFound {
let res = self.get(&key, None).await?.ok_or_else(|| Error::TbNotFound {
value: tb.to_owned(),
});
// Check whether the value exists in the datastore
Expand Down

0 comments on commit f795434

Please sign in to comment.