i5hi / slider_captcha_server

a slider captcha puzzle creation and verification library to protect http apis
GNU General Public License v3.0
2 stars 4 forks source link

Added verify_puzzle function on lib.rs #3

Closed yshwanth closed 1 year ago

yshwanth commented 1 year ago

Updated the example code of actix server

i5hi commented 1 year ago

few nits to address:

rust doesnt require you to use ; when returning . If you dont use ; it implies return, and also doesnt need the return key word.

you only need to use the return keyword if you want to return from inside an inner scope, for example from inside a match statement.

 if check < error_margin {
        return true;
    } else {
        return false;
    }

can just be

     if check < error_margin {
      true
    } else {
        false
    }
i5hi commented 1 year ago

there are some parts of the example where you have added ; to some returns, these are also unecessary

i5hi commented 1 year ago

also noticed you have made some formatting changes, so we might as well unify it across the project.

  1. use cargo clippy
  2. get rust-analyzer plugin in vscode which auto formats when you use Ctrl+Shift+i.
  3. Make sure tabs are configured to 4 spaces
  4. Where possible group imports in {}
yshwanth commented 1 year ago

let check = (solution - submission).abs(); check < error_margin

This is valid too, running cargo clippy

i5hi commented 1 year ago

let check = (solution - submission).abs(); check < error_margin

This is valid too, running cargo clippy

you can go one step better and avoid creating a variable check - will be more memory optimized

i5hi commented 1 year ago

Good one!

Thanks!