Skip to main content

ExpectProjection

Trait ExpectProjection 

Source
pub trait ExpectProjection<'e, T, U>
where T: Debug + 'e, U: Debug + 'e,
{ // 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§

Source

fn projected_by<F>( self, projection: F, ) -> ProjectedExpectationsBuilder<'e, Self, T, U>
where F: Fn(&T) -> U + 'e, Self: Sized + ExpectationBuilder<'e, Value = T>,

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);
Source

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>,

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 });

Implementors§

Source§

impl<'e, T, U, B> ExpectProjection<'e, T, U> for B
where T: Debug + 'e, U: Debug + 'e, B: ExpectationBuilder<'e, Value = T>,