pub struct MemoryTransport { /* private fields */ }Expand description
A Transport that answers from a script and records what it was asked.
use futures::TryStreamExt;
use plexus_client::{decode, MemoryTransport, MethodRef, Transport};
#[derive(serde::Serialize, serde::Deserialize, Debug, PartialEq)]
struct Ev { n: u8 }
const COUNT: MethodRef = MethodRef::new("demo", "count");
let t = MemoryTransport::new().script_events(COUNT, &[Ev { n: 1 }, Ev { n: 2 }]);
let events = futures::executor::block_on(async {
decode::<Ev>(t.call(COUNT, serde_json::json!({}))).try_collect::<Vec<_>>().await
})
.unwrap();
assert_eq!(events, vec![Ev { n: 1 }, Ev { n: 2 }]);
assert_eq!(t.params_of(COUNT), Some(serde_json::json!({})));Implementations§
Source§impl MemoryTransport
impl MemoryTransport
pub fn new() -> Self
Sourcepub fn script(self, method: MethodRef, items: Vec<StreamItem>) -> Self
pub fn script(self, method: MethodRef, items: Vec<StreamItem>) -> Self
Script the raw wire items a method answers with. Use this to exercise
the shapes only a real transport produces — progress, an in-band
error, a data item with the wrong payload.
Sourcepub fn script_failure(self, method: MethodRef, error: TransportError) -> Self
pub fn script_failure(self, method: MethodRef, error: TransportError) -> Self
Script a transport failure — the connection dying instead of the server answering.
Sourcepub fn script_events<E: Serialize>(
self,
method: MethodRef,
events: &[E],
) -> Self
pub fn script_events<E: Serialize>( self, method: MethodRef, events: &[E], ) -> Self
Script the happy path: each event becomes a data item stamped with
the method’s content_type, followed by done.
Serialization uses the event type’s own Serialize, so a script
written against the server’s event enum cannot drift from what the
server would actually put on the wire.
Trait Implementations§
Source§impl Debug for MemoryTransport
impl Debug for MemoryTransport
Source§impl Default for MemoryTransport
impl Default for MemoryTransport
Source§impl Transport for MemoryTransport
impl Transport for MemoryTransport
fn call(&self, method: MethodRef, params: Value) -> ItemStream<'_>
Source§fn call_raw(&self, method: MethodRef, params: Value) -> RawItemStream<'_>
fn call_raw(&self, method: MethodRef, params: Value) -> RawItemStream<'_>
call for a typed client (PERF.115-36): the same items,
each data item’s content still the wire’s JSON, which
decode_raw decodes straight into the method’s
event. The default is call’s items, each content the Value it
carries; a transport that has the wire’s text (WsTransport) hands it
over unread.Source§fn call_with_input<'a>(
&'a self,
method: MethodRef,
params: Value,
input: InputItems<'a>,
) -> ItemStream<'a>
fn call_with_input<'a>( &'a self, method: MethodRef, params: Value, input: InputItems<'a>, ) -> ItemStream<'a>
BIDIR-6:
call, for a method with an input half:
input is sent as the call runs, under the callee’s credit, and ended
when it ends. A transport that carries no input half (the default)
says so in the one item it yields: the call does not hang.Source§fn call_raw_with_input<'a>(
&'a self,
method: MethodRef,
params: Value,
input: InputItems<'a>,
) -> RawItemStream<'a>
fn call_raw_with_input<'a>( &'a self, method: MethodRef, params: Value, input: InputItems<'a>, ) -> RawItemStream<'a>
BIDIR-6:
call_raw, for a method with an input
half: what a typed client’s method with an Input calls. The default
is call_with_input’s items, each content
the Value it carries.Auto Trait Implementations§
impl !Freeze for MemoryTransport
impl Forget for MemoryTransport
impl RefUnwindSafe for MemoryTransport
impl Send for MemoryTransport
impl Sync for MemoryTransport
impl Unpin for MemoryTransport
impl UnsafeUnpin for MemoryTransport
impl UnwindSafe for MemoryTransport
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more