#unwrap_or_else error

7 messages · Page 1 of 1 (latest)

burnt radish
#

No two futures are the same type, so your unwrap_or_else can't work.

#

The future in the Option is not the same type as the future your async {} makes

sturdy sierra
#

i'd recommend assigning some things to intermediate variables rather than making one big statement. It might help if the types are more obvious

burnt radish
#

Ah, then yeah, it's that unwrap_or_else doesn't support awaiting through it

#

You can use match, though

#
let amount = get_activity(req, page, contract_address, token_id)
  .await?
  .results
  .iter()
  .find_map(|action| (action.kind == "sale") //renamed this to workaround the bug in syntax highlighting
  .then_some(action.value.amount.parse::<u64>().unwrap());
Ok(match amount {
  Some(x) => x,
  None => super::collections::get_stats(req, contract_address, rtype).await.unwrap().floor_price_in_cents,
})
#

Basically, just write the impl of unwrap_or_else