1

Is there a way to use String::from with variables? I tried using it similarly to println!(), but doesn't seem to work.

String::from("[INFO]: {}", message) Expected: // Returns: "[INFO]: My info message here" Got: // Error: argument unexpected 
1
  • 4
    Sounds like you want to use format! Commented Oct 28, 2022 at 10:01

1 Answer 1

0

Rust doesn’t really practice variadic functions because we have big metaprogramming potential: modern generic system and about 6 types of macros.

In this case you need the format macro:

format!("[INFO]: {}", message) 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.