Out of scope error using `colored` crate

Getting an error trying to use the colored crate:

error[E0425]: cannot find function `green` in this scope
   --> src/main.rs:134:30
    |
134 |     println!("this is green".green());
    |                              ^^^^^ not found in this scope

My code is simply following the directions from the docs. I imported the package via cargo add colored.

use colored::Colorize;

pub fn main() {
    println!("this is green".green());
}

println takes a format string as it's first argument. You need to write:

println!("{}", "your text".green())

If this is the whole diagnostic output from rustc, I would maybe report that to the error diagnostic team. It's a bit lacking.

Edit: the compiler should also have pointed the error to you with those error messages:

error: expected `,`, found `.`
  --> src/main.rs:10:29
   |
10 |     println!("this is green".green());
   |                             ^ expected `,`

error: argument never used
  --> src/main.rs:10:30
   |
10 |     println!("this is green".green());
   |              --------------- ^^^^^^^ argument never used
   |              |
   |              formatting specifier missing
1 Like

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.