我该如何使一个const
字符串的一部分根据某个标志条件化?
#[cfg(target_os = "macos")]
const OS: &'static str = "OSx";
#[cfg(target_os = "windows")]
const OS: &'static str = "Windows";
const SOME_STRING: &'static str = format!("this os is {}", OS);
这段代码无法编译,因为format
宏返回一个String
。我希望能够进行格式化而不进行任何分配。是否可能在不使整个字符串条件化的情况下实现此操作?