pub trait RevGetMultiFieldImpl<'a, This: ?Sized + 'a>: IsMultiFieldPath + Sized {
type UnnormFields: 'a + NormalizeFields;
// Required method
fn rev_get_multi_field_impl(self, this: &'a This) -> Self::UnnormFields;
}
Expand description
Gets references to multiple fields from This
,
usually a tuple of Result<&_, E: IsFieldErr>
s,
This
is the type we are accessing,and Self
is a field path.
To get Option<&_>
or &_
instead of each of those Result
s,
you can use the RevGetMultiField
as a bound instead.
§Usage as bound
This trait shouldn’t be used as a bound,except in implementations of the same trait.
For a trait that can be used in bounds,you can use RevGetMultiField
(it has examples).
§Example
This example demonstrates how you can implement RevGetMultiFieldImpl
to get a
pair of indices.
use structural::field::{FailedAccess, RevGetMultiFieldImpl};
use structural::path::{AliasedPaths, IsMultiFieldPath};
use structural::StructuralExt;
struct Pair(usize,usize);
impl IsMultiFieldPath for Pair{
type PathUniqueness= AliasedPaths;
}
impl<'a,T:'a> RevGetMultiFieldImpl<'a,[T]> for Pair{
type UnnormFields=(
Result<&'a T,FailedAccess>,
Result<&'a T,FailedAccess>,
);
fn rev_get_multi_field_impl(self, this: &'a [T]) -> Self::UnnormFields{
(
this.get(self.0).ok_or(FailedAccess),
this.get(self.1).ok_or(FailedAccess),
)
}
}
let arr=[2,3,5,8,13,21,34,55,89];
assert_eq!( arr[..].fields(Pair(2,1)), (Some(&5),Some(&3)) );
assert_eq!( arr[..].fields(Pair(0,3)), (Some(&2),Some(&8)) );
Required Associated Types§
Sourcetype UnnormFields: 'a + NormalizeFields
type UnnormFields: 'a + NormalizeFields
A collection of Results<&'a _,_>
s referencing fields.
Required Methods§
Sourcefn rev_get_multi_field_impl(self, this: &'a This) -> Self::UnnormFields
fn rev_get_multi_field_impl(self, this: &'a This) -> Self::UnnormFields
Gets references to multiple fields from this
.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.