Not able to print captured variable to output

Why I am not able to see the col_index label and value and c label and value in my output? Please help!

row.chars()
.enumerate()
.map(|(col, c)| match c {
CRCT => CRCT,
_ => count_char(col_index, row_index, charfield),
})
.inspect(|col_index| println!("col_index {}", &col_index))
.inspect(|c| println!("c {}", &c))

            .collect::<String>()
    })                   
    .collect()

//and so on

What error are you getting?

Also, could you update the code to match the formatting guidelines?

1 Like

No compile error or warning. Just no output.

Sorry about formatting. I will correct it tomorrow.

The Rust Programming Language Forum

Not able to print captured variable to output

help

Do you want live notifications when people reply to your posts? Enable Notifications​

Do you want to install The Rust Programming Language Forum on this device?​

Not able to print captured variable to output

help

1

/

3

fooly

1

4h

Why I am not able to see the col_index label and value and c label and value in my output? Please help!

Attempted format correction on Android Phone:

row.chars()
.enumerate()
.map(|(col, c)| match c {
CRCT => CRCT,
_=> count_char(col_index, row_index, charfield),
})
.inspect(|col_index| println!("col_index {}", &col_index))
.inspect(|c| println!("c {}", &c))
.collect::()
})
.collect()

//and so

Could you provide a complete example please?

I tried copying your code snippet into the playground but it fails to compile due to a bunch of missing variables and functions. There was also a syntax error because you've got a trailing }).collect(), but I'm guessing that was an accident from when you copy/pasted the code into your post.

fn main() {
    let row = "this is a string";

    row.chars()
        .enumerate()
        .map(|(col, c)| match c {
            CRCT => CRCT,
            _ => count_char(col_index, row_index, charfield),
        })
        .inspect(|col_index| println!("col_index {}", &col_index))
        .inspect(|c| println!("c {}", &c))
        .collect::<String>();
}

(playground)

   Compiling playground v0.0.1 (/playground)
error[E0425]: cannot find function `count_char` in this scope
 --> src/main.rs:8:18
  |
8 |             _ => count_char(col_index, row_index, charfield),
  |                  ^^^^^^^^^^ not found in this scope

error[E0425]: cannot find value `col_index` in this scope
 --> src/main.rs:8:29
  |
8 |             _ => count_char(col_index, row_index, charfield),
  |                             ^^^^^^^^^ not found in this scope

error[E0425]: cannot find value `row_index` in this scope
 --> src/main.rs:8:40
  |
8 |             _ => count_char(col_index, row_index, charfield),
  |                                        ^^^^^^^^^ not found in this scope

error[E0425]: cannot find value `charfield` in this scope
 --> src/main.rs:8:51
  |
8 |             _ => count_char(col_index, row_index, charfield),
  |                                                   ^^^^^^^^^ not found in this scope

For more information about this error, try `rustc --explain E0425`.
error: could not compile `playground` due to 4 previous errors

Something that often helps people with reproducing your issue is if you can write up a minimal example on the playground. That way we have all the code and can hit the "build" button to see any compile errors you are having.

Thank you. I will work on runnable code on Playground.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.