[syntax game] Taking Ownership of a String Multiple Times?
⚓ Rust 📅 2025-09-20 👤 surdeus 👁️ 8How to make the following code to pass the compilation? ![]()
Rules:
- You cannot modify the function, you are only allowed to add code surrounding it.
- You can use macros, but when all macros expand the code must exist, which means it's not allowed to use
#[cfg(...)]orstringify!to hide that function. - You cannot put it inside comments (
/* */) or string literals (" "). - There is at least one workaround exists, maybe more.
- Must be able to compile in Playground.
fn foo() -> String {
let a: String = "a".to_string();
let b = a;
let c = a;
a
}
5 posts - 4 participants
🏷️ Rust_feed