From af1c088507c0917bbf702b3a74eec1b61b4c6dbb Mon Sep 17 00:00:00 2001 From: Nettika Date: Sat, 9 Jul 2022 12:15:03 -0700 Subject: [PATCH] Rename wrapper struct to "Valid" --- readme.md | 2 +- src/lib.rs | 16 ++++++++-------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/readme.md b/readme.md index 8f0adb5..a2453b1 100644 --- a/readme.md +++ b/readme.md @@ -12,7 +12,7 @@ vet = "0.1" ``` ```rust -use vet::{Vet, Vetted}; +use vet::Vet; #[derive(Debug)] struct Username(String); diff --git a/src/lib.rs b/src/lib.rs index 5ad451f..05ce3c8 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -6,9 +6,9 @@ //! //! The `Vet` trait also provides a default implementation of a `vet` method //! which, dependant on the result of `is_valid`, either wraps the instance with -//! a `Vetted` struct or propagates the validation error. +//! a `Valid` struct or propagates the validation error. //! -//! The `Vetted` wrapper guarantees that the inner value was successfully +//! The `Valid` wrapper guarantees that the inner value was successfully //! validated and remains immutable as long as it is wrapped. //! //! Implementations for the common standard library types `Vec` and @@ -17,7 +17,7 @@ //! # Examples //! //! ``` -//! use vet::{Vet, Vetted}; +//! use vet::{Valid, Vet}; //! //! #[derive(Debug)] //! struct Username(String); @@ -57,7 +57,7 @@ //! } //! } //! -//! fn create_account(username: Vetted) { +//! fn create_account(username: Valid) { //! println!("Account {:?} created", username); //! } //! ``` @@ -69,9 +69,9 @@ extern crate alloc; /// A wrapper around a validated instance #[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)] -pub struct Vetted(T); +pub struct Valid(T); -impl core::ops::Deref for Vetted { +impl core::ops::Deref for Valid { type Target = T; fn deref(&self) -> &Self::Target { @@ -88,12 +88,12 @@ pub trait Vet { fn is_valid(&self) -> Result<(), Self::VetError>; /// Validates this instance and results in a wrapped instance if successful. - fn vet(self) -> Result, Self::VetError> + fn vet(self) -> Result, Self::VetError> where Self: Sized, { match self.is_valid() { - Ok(()) => Ok(Vetted(self)), + Ok(()) => Ok(Valid(self)), Err(e) => Err(e), } }