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
impl Variables
Sourcepub fn from_json(json: &Value) -> Result<Self, String>
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();Sourcepub fn insert_value(&mut self, name: String, value: Value)
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()));Sourcepub fn insert_string(&mut self, name: String, value: String)
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());Sourcepub fn insert_int(&mut self, name: String, value: i64)
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);Sourcepub fn insert_float(&mut self, name: String, value: f64)
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);Sourcepub fn insert_bool(&mut self, name: String, value: bool)
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);Sourcepub fn insert_null(&mut self, name: String)
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());