pub trait IteratorExt: IntoIterator {
// Required methods
fn validate_all_in_context<I>(
self,
ctx: &<Self::Item as Validate>::Context,
) -> Result<I, <Self::Item as Validate>::Error>
where Self::Item: Validate,
I: Extend<<Self::Item as Validate>::Output> + Default;
fn validate_all<I>(self) -> Result<I, <Self::Item as Validate>::Error>
where Self::Item: Validate,
<Self::Item as Validate>::Context: From<()>,
I: Extend<<Self::Item as Validate>::Output> + Default;
fn partition_validated_in_context<I1, I2>(
self,
ctx: &<Self::Item as Validate>::Context,
) -> (I1, I2)
where Self::Item: Validate,
I1: Extend<<Self::Item as Validate>::Output> + Default,
I2: Extend<<Self::Item as Validate>::Error> + Default;
fn partition_validated<I1, I2>(self) -> (I1, I2)
where Self::Item: Validate,
<Self::Item as Validate>::Context: From<()>,
I1: Extend<<Self::Item as Validate>::Output> + Default,
I2: Extend<<Self::Item as Validate>::Error> + Default;
async fn resolve_all_in_context<I>(
self,
ctx: &<Self::Item as Resolve>::Context,
) -> Result<I, <Self::Item as Resolve>::Error>
where Self: Sized,
Self::Item: Resolve,
I: Extend<<Self::Item as Resolve>::Output> + Default;
async fn resolve_all<I>(self) -> Result<I, <Self::Item as Resolve>::Error>
where Self: Sized,
Self::Item: Resolve,
<Self::Item as Resolve>::Context: From<()>,
I: Extend<<Self::Item as Resolve>::Output> + Default;
async fn partition_resolved_in_context<I1, I2>(
self,
ctx: &<Self::Item as Resolve>::Context,
) -> (I1, I2)
where Self: Sized,
Self::Item: Resolve,
I1: Extend<<Self::Item as Resolve>::Output> + Default,
I2: Extend<<Self::Item as Resolve>::Error> + Default;
async fn partition_resolved<I1, I2>(self) -> (I1, I2)
where Self: Sized,
Self::Item: Resolve,
<Self::Item as Resolve>::Context: From<()>,
I1: Extend<<Self::Item as Resolve>::Output> + Default,
I2: Extend<<Self::Item as Resolve>::Error> + Default;
}Expand description
Required Methods§
Sourcefn validate_all_in_context<I>(
self,
ctx: &<Self::Item as Validate>::Context,
) -> Result<I, <Self::Item as Validate>::Error>
fn validate_all_in_context<I>( self, ctx: &<Self::Item as Validate>::Context, ) -> Result<I, <Self::Item as Validate>::Error>
Validates every item within given context, short-circuiting on the first error.
Sourcefn validate_all<I>(self) -> Result<I, <Self::Item as Validate>::Error>
fn validate_all<I>(self) -> Result<I, <Self::Item as Validate>::Error>
Context-free variant of validate_all_in_context, available when item Context = ().
§Examples
use peer_pressure::{Validate, IteratorExt};
struct RawNum(i32);
struct Positive(i32);
impl Validate for RawNum {
type Context = ();
type Output = Positive;
type Error = &'static str;
fn validate_in_context(self, _: &()) -> Result<Positive, &'static str> {
if self.0 > 0 { Ok(Positive(self.0)) } else { Err("non-positive") }
}
}
let raws = [RawNum(1), RawNum(2), RawNum(3)];
let out: Result<Vec<_>, _> = raws.validate_all();
assert!(out.is_ok());Sourcefn partition_validated_in_context<I1, I2>(
self,
ctx: &<Self::Item as Validate>::Context,
) -> (I1, I2)
fn partition_validated_in_context<I1, I2>( self, ctx: &<Self::Item as Validate>::Context, ) -> (I1, I2)
Validates every item within given context, partitioning successes into I1 and errors into I2.
Sourcefn partition_validated<I1, I2>(self) -> (I1, I2)
fn partition_validated<I1, I2>(self) -> (I1, I2)
Context-free variant of partition_validated_in_context, available when items’ Context = ().
Input order is preserved within each output collection.
§Examples
use peer_pressure::{Validate, IteratorExt};
struct RawNum(i32);
struct Positive(i32);
impl Validate for RawNum {
type Context = ();
type Output = Positive;
type Error = &'static str;
fn validate_in_context(self, _: &()) -> Result<Positive, &'static str> {
if self.0 > 0 { Ok(Positive(self.0)) } else { Err("non-positive") }
}
}
let raws = [RawNum(1), RawNum(-1), RawNum(2)];
let (oks, errs): (Vec<Positive>, Vec<&'static str>) = raws.partition_validated();
assert_eq!(oks.len(), 2);
assert_eq!(errs, vec!["non-positive"]);Sourceasync fn resolve_all_in_context<I>(
self,
ctx: &<Self::Item as Resolve>::Context,
) -> Result<I, <Self::Item as Resolve>::Error>
Available on crate feature async only.
async fn resolve_all_in_context<I>( self, ctx: &<Self::Item as Resolve>::Context, ) -> Result<I, <Self::Item as Resolve>::Error>
async only.Resolves every item within given context, short-circuiting on the first error.
Sourceasync fn resolve_all<I>(self) -> Result<I, <Self::Item as Resolve>::Error>
Available on crate feature async only.
async fn resolve_all<I>(self) -> Result<I, <Self::Item as Resolve>::Error>
async only.Context-free variant of resolve_all_in_context, available when items’ Context = ().
Sourceasync fn partition_resolved_in_context<I1, I2>(
self,
ctx: &<Self::Item as Resolve>::Context,
) -> (I1, I2)
Available on crate feature async only.
async fn partition_resolved_in_context<I1, I2>( self, ctx: &<Self::Item as Resolve>::Context, ) -> (I1, I2)
async only.Resolves every item within given context, partitioning successes into I1 and errors into I2.
Sourceasync fn partition_resolved<I1, I2>(self) -> (I1, I2)
Available on crate feature async only.
async fn partition_resolved<I1, I2>(self) -> (I1, I2)
async only.Context-free variant of partition_resolved_in_context, available when items’ Context = ().
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".