Implement unwrapping method
This commit is contained in:
parent
cb57718f94
commit
02890e635c
2 changed files with 9 additions and 0 deletions
|
|
@ -65,6 +65,8 @@ fn main() {
|
|||
// Any `Valid<Username>` passed is guaranteed
|
||||
// to have met the arbitrary validation checks.
|
||||
fn create_account(username: Valid<Username>) {
|
||||
let username = username.into_inner(); // Unwrap
|
||||
|
||||
println!("Account {:?} created", username);
|
||||
}
|
||||
```
|
||||
|
|
|
|||
|
|
@ -74,6 +74,13 @@ mod tests;
|
|||
#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
|
||||
pub struct Valid<T>(T);
|
||||
|
||||
impl<T> Valid<T> {
|
||||
/// Consumes the `Valid` wrapper, returning the wrapped value.
|
||||
pub fn into_inner(self) -> T {
|
||||
self.0
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> core::ops::Deref for Valid<T> {
|
||||
type Target = T;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue