pub fn request_value(&mut self, format: &Value) -> String {
        let mut format = format!("{}", format);

        if format.len() <= 6 {
            return format;
        };

        match format.get(0..3).unwrap() {
            "\"{{" => {
                match format.get(format.len() - 3..format.len()).unwrap() {
                    "}}\"" => {
                        format.retain(|c| !c.is_whitespace());
                        match format.get(3..4).unwrap() {
                            ">" => {
                                let colon_offset = format.find(":").unwrap();

                                let variable_name = format.get(4..colon_offset).unwrap();

                                let variable_type =
                                    format.get((colon_offset + 1)..(format.len() - 3)).unwrap();

                                let mut variable_value = self.request_user_input(variable_name);

                                variable_value = String::from(variable_value.trim());
                                // Wrapping the value by quotes if string
                                if variable_type == "string" {
                                    let mut new_variable_value = String::from("\"");
                                    new_variable_value.push_str(&variable_value);
                                    new_variable_value.push_str("\"");
                                    variable_value = new_variable_value;
                                }

                                let mut entered_value = from_str(&variable_value.clone())
                                    .expect("Invalid value entered!");

                                let check_type = type_check(variable_type, &entered_value);

                                if !check_type {
                                    variable_value = get_default_value(variable_type).expect(
                                        &format!("Unsupported type given for {}.", variable_name),
                                    );
                                    println!("{} : Type not matching for the variable '{}'. Assigned the default value.","WARN".yellow(),variable_name);
                                    entered_value = from_str(&variable_value).unwrap();
                                }

                                self.variables.add(variable_name, entered_value);

                                variable_value
                            }
                            _ => {
                                match self
                                    .variables
                                    .get(&format.get(3..(format.len() - 3)).unwrap())
                                {
                                    Some(variable) => format!("{}", variable.value),
                                    None => panic!("Can not find a variable named {}", format),
                                }
                            }
                        }
                    }
                    _ => format,
                }
            }
            _ => format,
        }
    }
/// Passing a pattern in a request body
Passing a pattern in a request body
Passing a pattern in a request body
pub fn request_value(&mut self, format: &Value) -> String {
        let mut format = format!("{}", format);
        if format.len() <= 6 {
            return format;
        };
        match format.get(0..3).unwrap() {
            "\"{{" => {
                match format.get(format.len() - 3..format.len()).unwrap() {
                    "}}\"" => {
                        format.retain(|c| !c.is_whitespace());
                        match format.get(3..4).unwrap() {
                            ">" => {
                                let colon_offset = format.find(":").unwrap();
                                let variable_name = format.get(4..colon_offset).unwrap();
                                let variable_type =
                                    format.get((colon_offset + 1)..(format.len() - 3)).unwrap();
                                let mut variable_value = self.request_user_input(variable_name);
                                variable_value = String::from(variable_value.trim());
                                // Wrapping the value by quotes if string
                                if variable_type == "string" {
                                    let mut new_variable_value = String::from("\"");
                                    new_variable_value.push_str(&variable_value);
                                    new_variable_value.push_str("\"");
                                    variable_value = new_variable_value;
                                }
                                let mut entered_value = from_str(&variable_value.clone())
                                    .expect("Invalid value entered!");
                                let check_type = type_check(variable_type, &entered_value);
                                if !check_type {
                                    variable_value = get_default_value(variable_type).expect(
                                        &format!("Unsupported type given for {}.", variable_name),
                                    );
                                    println!("{} : Type not matching for the variable '{}'. Assigned the default value.","WARN".yellow(),variable_name);
                                    entered_value = from_str(&variable_value).unwrap();
                                }
                                self.variables.add(variable_name, entered_value);
                                variable_value
                            }
                            _ => {
                                match self
                                    .variables
                                    .get(&format.get(3..(format.len() - 3)).unwrap())
                                {
                                    Some(variable) => format!("{}", variable.value),
                                    None => panic!("Can not find a variable named {}", format),
                                }
                            }
                        }
                    }
                    _ => format,
                }
            }
            _ => format,
        }
    }
pub fn request_value ( & mut self , format : & Value ) -> String { let mut format = format ! ( " " format ) ; if format . len ( ) <= 6 { return format ; } ; match format . get ( 0 .. 3 ) . unwrap ( ) { " \" " => { match format . get ( format . len ( ) - 3 .. format . len ( ) ) . unwrap ( ) { " \" " => { format . retain ( | c | ! c . is_whitespace ( ) ) ; match format . get ( 3 .. 4 ) . unwrap ( ) { " " => { let colon_offset = format . find ( " " ) . unwrap ( ) ; let variable_name = format . get ( 4 .. colon_offset ) . unwrap ( ) ; let variable_type = format . get ( ( colon_offset + 1 ) .. ( format . len ( ) - 3 ) ) . unwrap ( ) ; let mut variable_value = self . request_user_input ( variable_name ) ; variable_value = String :: from ( variable_value . trim ( ) ) ; // Wrapping the value by quotes if string if variable_type == " " { let mut new_variable_value = String :: from ( " \" " ) ; new_variable_value . push_str ( & variable_value ) ; new_variable_value . push_str ( " \" " ) ; variable_value = new_variable_value ; } let mut entered_value = from_str ( & variable_value . clone ( ) ) . expect ( " " ) ; let check_type = type_check ( variable_type , & entered_value ) ; if ! check_type { variable_value = get_default_value ( variable_type ) . expect ( & format ! ( " " variable_name ) , ) ; println ! ( " " " " yellow ( ) variable_name ) ; entered_value = from_str ( & variable_value ) . unwrap ( ) ; } self . variables . add ( variable_name , entered_value ) ; variable_value } _ => { match self . variables . get ( & format . get ( 3 .. ( format . len ( ) - 3 ) ) . unwrap ( ) ) { Some ( variable ) => format ! ( " " variable value ) , None => panic ! ( " " format ) , } } } } _ => format , } } _ => format , } }
Passing a pattern in a request body
Passing a pattern in a request body
&mut self
format
&Value