Working with Iron library


Hi all.
Here is my problem. I add routing to my server, but it accepts an rec:&mut Request in a closure as a handler for the rout in which i call my func ( a real handler for the rout) where i pass this rec as &mut Request.
But i call an fn in the real handler to check for the Method of the Request, it looks like this:

fn handler_helper(rec:&mut Request,method:Method,vectors:&mut Helper,string:&mut String)->i32{
match rec.method{
_=>{return 1;}

But recieve cannot move out of borrowed context
I tried the Clone trait for Request but recieved
impl Clone for Request{
| ^^^^^^^ expected 2 lifetime parameters

How can i solve this problem???


When will you start using code blocks to format snippets? :slight_smile:

fn handler_helper(rec:&mut Request,method:Method,vectors:&mut Helper,string:&mut String)->i32{
match rec.method {
method => {}
_=>{return 1;}

The above doesn’t do what you think it does. Are you trying to see if rec.method == method? What it’s doing now is creating a new binding in the match, called “method”, and then trying to move rec.method into it. Note this binding will match any rec.method and the other arm of your match is unreachable. It’s basically doing let method = rec.method.


Sir i have solved the problem replacing my match with if else stmt.
Another thing i want to ask is next:
I have next body of my equest:
As you can see it is an array of json strings, and the code passes the check if the body was a json format.

fn handler_helper(rec:&mut Request,method:Method,vectors:&mut Helper,string:&mut String)->i32{

let mut string1=String::new();
rec.body.read_to_string(&mut string1);
let mut json_string=serde_json::from_str(&string1);
let json_string1:Value;
match json_string{
Ok(x)=> {json_string1=x;}
Err(_)=> {return 2;}
if json_string1.is_array() {
for i in 0… {
if json_string1[i].is_null() {
parse_json(vectors, &json_string1[i][“id”], 1, string);
parse_json(vectors, &json_string1[i][“login”], 2, string);
parse_json(vectors, &json_string1[i][“password”], 3, string);
parse_json(vectors, &json_string1[i][“email”], 4, string);

But it does not see any fields at all.
The goal is to find out how to go through all json strings in received Array and to get all id,login,password,email fields. My parse_json function is recursive if the field is an object or an array it will get into it anyway and will reach the initial value if such exists in that field.


In the body json array slashes hasnt been shown in the previous message.