Suppress warning in Rocket framework

Hello folks,

I am currently creating my Rust server using Rocket and

#[get("/hello/<name>")]
fn hello(name: String) -> String {
    format!("Hello, {} !", name)
}

And when i send request to: http://127.0.0.1/hello/test

I get

šŸš€ Rocket has launched from http://127.0.0.1:8000
GET /hello/test:
   >> Matched: (hello) GET /v1/item/create/<name>
   >> Note: Using `String` as a parameter type is inefficient. Use `&str` instead.
   >> `String` is used a parameter guard in src/main.rs:24.
   >> Outcome: Success(200 OK)
   >> Response succeeded.

Without changing the String to &str how can i suppress these two messages: Note: Using String as a parameter type is inefficient. Use &str instead. >> String is used a parameter guard in src/main.rs:24.

Thank you.

I guess you want to set the LogLevel to LogLevel::Critical or LogLevel::Off if Critical still displays the warning. A guide on how you can configure Rocket can be found here: Configuration - Rocket Web Framework. I.e. you could add the following to your Rocket.toml:

[default]
log_level = "critical"

and see if that removes the warning.

You could also change the type of the name parameter from String to &str, and the warning will go away.

3 Likes

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.