add attributes to Validated methods (#2555)

This commit is contained in:
Mai 2024-08-08 16:00:57 +03:00 committed by GitHub
parent 45ff753e77
commit 2aafcf9a3d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -389,6 +389,7 @@ pub enum Validated<E> {
impl<E> Validated<E> { impl<E> Validated<E> {
/// Maps the inner `Error` value using the provided function, or does nothing if the value is /// Maps the inner `Error` value using the provided function, or does nothing if the value is
/// `ValidationError`. /// `ValidationError`.
#[inline]
pub fn map<F>(self, f: impl FnOnce(E) -> F) -> Validated<F> { pub fn map<F>(self, f: impl FnOnce(E) -> F) -> Validated<F> {
match self { match self {
Self::Error(err) => Validated::Error(f(err)), Self::Error(err) => Validated::Error(f(err)),
@ -396,6 +397,7 @@ impl<E> Validated<E> {
} }
} }
#[inline]
fn map_validation(self, f: impl FnOnce(Box<ValidationError>) -> Box<ValidationError>) -> Self { fn map_validation(self, f: impl FnOnce(Box<ValidationError>) -> Box<ValidationError>) -> Self {
match self { match self {
Self::Error(err) => Self::Error(err), Self::Error(err) => Self::Error(err),
@ -404,6 +406,8 @@ impl<E> Validated<E> {
} }
/// Returns the inner `Error` value, or panics if it contains `ValidationError`. /// Returns the inner `Error` value, or panics if it contains `ValidationError`.
#[inline(always)]
#[track_caller]
pub fn unwrap(self) -> E { pub fn unwrap(self) -> E {
match self { match self {
Self::Error(err) => err, Self::Error(err) => err,