pub struct MethodArgs<'a> { /* private fields */ }Expand description
Decoder for the body of a struct method taking two or more arguments.
A single-argument method takes the request body as the argument, which is the shape the wire has always had. Beyond one argument the body carries the whole list, in either of two forms:
- a JSON/BEVE array of exactly N values, positionally, or
- an object keyed by parameter name, where a missing key decodes as
null(so anOption<T>parameter may be omitted) and a repeated key takes its last value.
All three BEVE array encodings work: generic, typed, and complex. They are
not read the same way — a generic array’s elements are self-contained values
in the input and are sliced out as spans, while a typed or complex array’s
element headers are supplied by the reader rather than present in the bytes,
so those are pulled through structio::beve::Documents::array instead — but
that is an implementation detail and not a wire distinction. A client encodes
a homogeneous argument list however its library naturally would.
Generated code names this, and a hand-written RepeMethods impl that
publishes a multi-argument method should too: it is what makes such a table
accept the same two body shapes a derived one does, instead of inventing a
third that no client of a derived struct would speak. That is why it is
public and documented rather than hidden — it carries a wire contract, not an
implementation detail.
§How it works without a tree
It used to split a serde_json::Value into owned Values. There is no tree
now, so it does the same job by recording byte spans: one pass over the
body notes where each element starts and ends, and
next_arg parses one span into one argument. Nothing
between the two is materialized, no key is copied, and an argument the caller
never asks for is never parsed.
The spans borrow the frame, which is why this carries the body’s lifetime.
Implementations§
Source§impl<'a> MethodArgs<'a>
impl<'a> MethodArgs<'a>
Sourcepub fn new(
path: &'a str,
names: &'a [&'a str],
body: RequestBody<'a>,
) -> StructResult<Self>
pub fn new( path: &'a str, names: &'a [&'a str], body: RequestBody<'a>, ) -> StructResult<Self>
Split body into the argument list for names.
Sourcepub fn next_arg<T>(&mut self) -> StructResult<T>where
T: for<'de> ServableRead<'de> + Default,
pub fn next_arg<T>(&mut self) -> StructResult<T>where
T: for<'de> ServableRead<'de> + Default,
Decode the next argument in declaration order.