Struct Variables

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

Variables to be used in the request and response bodies.

The variables are used to replace placeholders in the request and response bodies in case some values need to be shared between requests and responses.

§Examples

Variables can be passed one by one with specified type:

let mut variables = Variables::new();
variables.insert_string("name".to_string(), "John".to_string());
variables.insert_int("age".to_string(), 30);

A Value can be passed directly:

let mut variables = Variables::new();
variables.insert_value("name".to_string(), Value::String("John".to_string()));
variables.insert_value("age".to_string(), Value::Number(serde_json::Number::from(30)));

Alternatively, they can be passed as a JSON object:

let json = r#"{"name": "John", "age": 30}"#;
let variables = Variables::from_json(&serde_json::from_str(json).unwrap()).unwrap();

Implementations§

Source§

impl Variables

Source

pub fn new() -> Self

Constructs a new Variables.

§Examples
let variables = Variables::new();
Source

pub fn from_json(json: &Value) -> Result<Self, String>

Constructs a new Variables from a JSON object.

§Examples
let json = r#"{"name": "John", "age": 30}"#;
let variables = Variables::from_json(&serde_json::from_str(json).unwrap()).unwrap();
Source

pub fn insert_value(&mut self, name: String, value: Value)

Inserts a Value into the Variables.

This can be useful when more complex types are needed. Since Variables is a wrapper around HashMap if you insert duplicate keys the value will be overwritten.

§Examples
let mut variables = Variables::new();
variables.insert_value("name".to_string(), Value::String("John".to_string()));
Source

pub fn insert_string(&mut self, name: String, value: String)

Inserts a String into the Variables.

§Examples
let mut variables = Variables::new();
variables.insert_string("name".to_string(), "John".to_string());
Source

pub fn insert_int(&mut self, name: String, value: i64)

Inserts an i64 into the Variables.

§Examples
let mut variables = Variables::new();
variables.insert_int("age".to_string(), 30);
Source

pub fn insert_float(&mut self, name: String, value: f64)

Inserts an f64 into the Variables.

§Examples
let mut variables = Variables::new();
variables.insert_float("age".to_string(), 30.0);
Source

pub fn insert_bool(&mut self, name: String, value: bool)

Inserts a bool into the Variables.

§Examples
let mut variables = Variables::new();
variables.insert_bool("is_adult".to_string(), true);
Source

pub fn insert_null(&mut self, name: String)

Inserts a null into the Variables.

§Examples
let mut variables = Variables::new();
variables.insert_null("name".to_string());

Trait Implementations§

Source§

impl Clone for Variables

Source§

fn clone(&self) -> Variables

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Variables

Source§

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

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

impl Default for Variables

Source§

fn default() -> Variables

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,