pub trait ExpectProjection<'e, T, U>{
// Required methods
fn projected_by<F>(
self,
projection: F,
) -> ProjectedExpectationsBuilder<'e, Self, T, U>
where F: Fn(&T) -> U + 'e,
Self: Sized + ExpectationBuilder<'e, Value = T>;
fn projected_by_ref<F>(
self,
projection: F,
) -> ProjectedExpectationsBuilder<'e, Self, T, U>
where F: for<'a> Fn(&'a T) -> &'a U + 'e,
Self: Sized + ExpectationBuilder<'e, Value = T>;
}Expand description
Extension trait for adding expectations on a projected value.
Required Methods§
Sourcefn projected_by<F>(
self,
projection: F,
) -> ProjectedExpectationsBuilder<'e, Self, T, U>
fn projected_by<F>( self, projection: F, ) -> ProjectedExpectationsBuilder<'e, Self, T, U>
Add expectations on a projected value.
use rxpect::expect;
use rxpect::expectations::EqualityExpectations;
use rxpect::ExpectProjection;
#[derive(Debug)]
pub struct MyStruct {
pub foo: u32
}
expect(MyStruct{ foo: 7 }).projected_by(|it| it.foo).to_equal(7);Sourcefn projected_by_ref<F>(
self,
projection: F,
) -> ProjectedExpectationsBuilder<'e, Self, T, U>
fn projected_by_ref<F>( self, projection: F, ) -> ProjectedExpectationsBuilder<'e, Self, T, U>
Add expectations on a projected reference.
use rxpect::expect;
use rxpect::expectations::EqualityExpectations;
use rxpect::ExpectProjection;
#[derive(Debug)]
struct Parent {
child: Child,
}
#[derive(Debug, Eq, PartialEq)]
struct Child {
number: u32,
}
let value = Parent {
child: Child {
number: 7
},
};
expect(value)
.projected_by_ref(|s| &s.child)
.to_equal(Child { number: 7 });