Перейти к основному содержимому
Эта страница ещё не переведена

Ниже показан английский оригинал.

decoded_as

decoded_as::<U>() re-types a record, so its payload assertions decode to U.

out::<M>() returns an untyped record, because a slot may publish several types; decoded_as names the one to read. The same call reads a destination record as a type other than the one it was opened with. It consumes the record and keeps its messages and their recorded settings. After it, with, with_codec, decoded and decoded_with decode to U.

Example​

#[tokio::test]
async fn the_slot_sent_the_last_seat_last() -> Result<(), Box<dyn Error>> {
let tb = TestApp::start(app()).await?;
tb.broker::<MemoryBroker>()
.message(&Order { id: 7, seats: 2 })
.to("orders")
.publish()
.await?;

tb.out::<Tickets>()
.assert_called(2)
.decoded_as::<Ticket>()
.with(&Ticket {
order_id: 7,
seat: 2,
});
Ok(())
}