• python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Facebook Twitter Instagram
Devs Fixed
  • python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Devs Fixed
Home ยป Resolved: Is there an alternative expression for match in Rust?

Resolved: Is there an alternative expression for match in Rust?

0
By Isaac Tonny on 17/06/2022 Issue
Share
Facebook Twitter LinkedIn

Question:

I know that when handling errors using Result and Option, it can be expressed more concisely by using unwrap_or_else, unwrap_or_default, etc. instead of match.
The following is an example of expressing the match expression more concisely using unwrap.

Questions


Is there a function I can use instead of match if I want to put a return statement instead of putting a different value when an error occurs?

Answer:

You can use a combination of map_err() and the error propagation operator ?:

If you have better answer, please add a comment about this, thank you!

rust
Share. Facebook Twitter LinkedIn

Related Posts

Resolved: The ‘Access-Control-Allow-Origin’ header contains multiple values ‘*, *’, but only one is allowed. cors error not resolving

02/04/2023

Resolved: SQLSTATE[42S02]: Base table or view not found: 1146 Table ‘crm.email’ doesn’t exist (Connection: mysql, SQL: select count(*) as aggregate from `email`

02/04/2023

Resolved: Regex: Curly braces in reverse? Match X characters before a string?

02/04/2023

Leave A Reply

© 2023 DEVSFIX.COM

Type above and press Enter to search. Press Esc to cancel.