Skip to main content

Params

Struct Params 

Source
pub struct Params { /* private fields */ }
Expand description

Builds a call’s params object from typed arguments — what a generated client method does with its parameters before it calls the transport.

Keys are the method’s parameter names, which are what its schema declares. An Option parameter that is None is omitted, not sent as null (optional): the shape a server with skip_serializing_if = "Option::is_none" sends, and the one menger’s REST tests assert.

The first argument that does not serialize is kept as ClientError::Encode and build returns it — nothing is sent, and nothing panics (a panic in a wasm32 consumer is an unrecoverable trap).

use plexus_client::Params;

let params = Params::new()
    .param("id", "MNG-2")
    .optional("epic", None::<String>)
    .build()
    .unwrap();
assert_eq!(params, serde_json::json!({"id": "MNG-2"}));

Implementations§

Source§

impl Params

Source

pub fn new() -> Self

An empty params object — what a method with no parameters sends.

Source

pub fn param<V: Serialize>(self, name: &'static str, value: V) -> Self

Add name with value, always.

Source

pub fn optional<V: Serialize>( self, name: &'static str, value: Option<V>, ) -> Self

Add name when value is Some; omit it when None.

Source

pub fn build(self) -> Result<Value, ClientError>

The params object, or the first argument that would not encode.

Trait Implementations§

Source§

impl Debug for Params

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Params

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> MaybeSend for T
where T: Send,

Source§

impl<T> MaybeSendSync for T
where T: Send + Sync,

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.