Skip to content

Commit

Permalink
feat: rename traits to ValidFrom and ValidInto
Browse files Browse the repository at this point in the history
  • Loading branch information
tusharmath committed Dec 13, 2024
1 parent d0da788 commit 301bc1a
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,24 @@ pub use cause::*;
pub use valid::*;

/// Moral equivalent of TryFrom for validation purposes
pub trait ValidateFrom<T>: Sized {
pub trait ValidFrom<T>: Sized {
type Error;
type Trace;
fn validate_from(a: T) -> Valid<Self, Self::Error, Self::Trace>;
fn valid_from(a: T) -> Valid<Self, Self::Error, Self::Trace>;
}

/// Moral equivalent of TryInto for validation purposes
pub trait ValidateInto<T> {
pub trait ValidInto<T> {
type Error;
type Trace;
fn validate_into(self) -> Valid<T, Self::Error, Self::Trace>;
fn valid_into(self) -> Valid<T, Self::Error, Self::Trace>;
}

/// A blanket implementation for ValidateInto
impl<S, T: ValidateFrom<S>> ValidateInto<T> for S {
impl<S, T: ValidFrom<S>> ValidInto<T> for S {
type Error = T::Error;
type Trace = T::Trace;
fn validate_into(self) -> Valid<T, Self::Error, Self::Trace> {
T::validate_from(self)
fn valid_into(self) -> Valid<T, Self::Error, Self::Trace> {
T::valid_from(self)
}
}

0 comments on commit 301bc1a

Please sign in to comment.