Hello,
I'm a new rust developer, coming from object oriented languages, so I have a question about best practices on how to translate some concepts about getters/setters method.
Suppose I have a struct that mimics a record in a database:
struct User {
username: String,
password: String
}
This struct would be passed to some sort of database library that will create an INSERT sql statement and execute it.
Normally the password field would be encrypted with an algorhytm of some sort before being written to the db.
In an object oriented language I would make the username and password fields private and then declare methods like getUserrname, setUsername, getPassword and setPassword.
The setPassword method in particular would be something like this (I use php as an example):
function setPassword($value)
{
$this->password = encrpyt_magic_function($value);
}
This would allow me to always have valid values inside an instance of User because they are validated when setting them.
What are the best practices to achieve this sort of goal in Rust?
Thanks,
Frank