email_pass
Email
and Password
types in Rust.
Email data type
use Email;
Password data type
The type Password
differentiates the raw password from encrypted passwords and provides only the correct methods for each.
use Password;
The next code don't compile, because the raw passwords do not implement either the Display trait or the Debug trait.
use Password;
Legacy Password and Email types
You can use the old types behind the legacy
feature.
= { = "0.7.0", = ["legacy"] }
Password
use Password;
If the password is not encrypted, you can't access the inner value.
use Password;
The Password
type implements the Debug
trait securely.
You can construct the Email
with the new
method.
Serde Suport
The types Email
and Password
implements the traits Serialize
and Deserialize
in the feature serde
.
[]
= { = "0.7.0", = ["serde"] }
Migration from version 0.4.1 to version <= 0.7.0
If you don't want break your code, just use the feature legacy
:
[]
= { = "0.7.0", = ["legacy"] }
Then, you can try the new Password type with the import:
use Password;
Migration from version 0.4.1 to version 0.8.0+
Your code must have been broken when upgrading, because the v0.8.0
uses a new errors API, and uses a new Email constructors.
To fix your code:
- Adapt your error types to migrate to the new version.
- Replace all uses of
Deref
trait withPassword
type. - Replace all uses of
Email::new
method withEmail::build
orEmail::from_str
.
Migration from version 0.7.0 to version 0.8.0+
Same case as above. But if you use have been using both safe
and legacy
password types, you should choose only one.
Acknowledgments
Thanks to letsgetrusty for the
repo that inspired the Password
type.