I’ve just pushed an early draft of The Complete Rust Security Handbook.
Right now it’s a single Markdown file rendered by GitHub Pages - no fancy mdBook
UI yet, just raw content.
For your first example advertising the Newtype pattern:
fn transfer(from: UserId, to: UserId, amount: TokenAmount) -> Result<(), Error> {
// Now it's physically impossible to swap parameters!
}
The problem is still, that the first two arguments could be exchanged, so transferring the money in the wrong direction. Some other languages have named parameters, so that we had to call the function as transfer(from: User1, to: User2, amount: the_money);
I will bookmark your post, and perhaps read in in winter, thanks.
[EDIT]
Would using a transaction struct not be the better choice, as Rust has no named parameters?
struct Transaction {
from: UserID,
to: UserID,
amount: TokenAmount,
}
let action = Transaction{from: user1, to: user2, amount: amount};
let res = transfer(action);