mirror of
https://github.com/danbulant/cushy
synced 2026-07-06 03:30:38 +00:00
Validations::validate_result
This commit is contained in:
parent
641ae3a17d
commit
32cd07c241
2 changed files with 31 additions and 0 deletions
|
|
@ -24,6 +24,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||||
|
|
||||||
[92]: https://github.com/khonsulabs/gooey/issues/92
|
[92]: https://github.com/khonsulabs/gooey/issues/92
|
||||||
|
|
||||||
|
### Added
|
||||||
|
|
||||||
|
- `Validations::validate_result` attaches a `Dynamic<Result<T,E>>` to the
|
||||||
|
validations. This was already available on `when` conditioned validations.
|
||||||
|
|
||||||
## v0.1.3 (2023-12-19)
|
## v0.1.3 (2023-12-19)
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
|
|
|
||||||
26
src/value.rs
26
src/value.rs
|
|
@ -2243,6 +2243,32 @@ impl Validations {
|
||||||
validation
|
validation
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Returns a dynamic validation status that is created by transforming the
|
||||||
|
/// `Err` variant of `result` using [`Display`].
|
||||||
|
///
|
||||||
|
/// The validation is linked with `self` such that checking `self`'s
|
||||||
|
/// validation status will include this validation.
|
||||||
|
#[must_use]
|
||||||
|
pub fn validate_result<T, E>(
|
||||||
|
&self,
|
||||||
|
result: impl IntoDynamic<Result<T, E>>,
|
||||||
|
) -> Dynamic<Validation>
|
||||||
|
where
|
||||||
|
T: Send + 'static,
|
||||||
|
E: Display + Send + 'static,
|
||||||
|
{
|
||||||
|
let result = result.into_dynamic();
|
||||||
|
let error_message = result.map_each(move |value| match value {
|
||||||
|
Ok(_) => None,
|
||||||
|
Err(err) => Some(err.to_string()),
|
||||||
|
});
|
||||||
|
|
||||||
|
self.validate(&error_message, |error_message| match error_message {
|
||||||
|
None => Ok(()),
|
||||||
|
Some(message) => Err(message.clone()),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
fn map_to_message<T, E, Valid>(
|
fn map_to_message<T, E, Valid>(
|
||||||
mut check: Valid,
|
mut check: Valid,
|
||||||
) -> impl for<'a> FnMut(&'a GenerationalValue<T>) -> GenerationalValue<Option<String>> + Send + 'static
|
) -> impl for<'a> FnMut(&'a GenerationalValue<T>) -> GenerationalValue<Option<String>> + Send + 'static
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue