Skip to content

Commit

Permalink
Fix docs
Browse files Browse the repository at this point in the history
  • Loading branch information
aon committed Aug 10, 2023
1 parent d19f53a commit 7d7dbab
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions docs/docs/detectors/5-unused-return-enum.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,44 +14,45 @@ If definitions of Err() and/or Ok() are in the code but do not flow to the retur

### Example

Instead of using:

```rust
// example code where a warning is issued
// example code that does not raise a warning
#![cfg_attr(not(feature = "std"), no_std)]
pub enum TradingPairErrors {
Overflow,
}
(...)

#[ink(message)]
pub fn get_percentage_difference(&mut self, value1: Balance, value2: Balance) -> Result<Balance, TradingPairErrors> {
let absolute_difference = value1.abs_diff(value2);
let sum = value1 + value2;
let percentage_difference =
match 100u128.checked_mul(absolute_difference / sum) {
Some(result) => result,
None => Err(TradingPairErrors::Overflow),
}
Some(result) => Ok(result),
None => panic!("overflow!"),
};
return Err(TradingPairErrors::Overflow);
}
```

Use instead:
Use this:

```rust
// example code that does not raise a warning
#![cfg_attr(not(feature = "std"), no_std)]
pub enum TradingPairErrors {
Overflow,
}
(...)

#[ink(message)]
pub fn get_percentage_difference(&mut self, value1: Balance, value2: Balance) -> Result<Balance, TradingPairErrors> {
let absolute_difference = value1.abs_diff(value2);
let sum = value1 + value2;
let percentage_difference =
match 100u128.checked_mul(absolute_difference / sum) {
Some(result) => Ok(result),
None => panic!("overflow!"),
};
return Err(TradingPairErrors::Overflow);
Some(result) => result,
None => Err(TradingPairErrors::Overflow),
}
}
```

Expand Down

0 comments on commit 7d7dbab

Please sign in to comment.