相关疑难解决方法(0)

如何连接字符串?

如何连接以下类型组合:

  • strstr
  • Stringstr
  • StringString

string string-concatenation rust

133
推荐指数
6
解决办法
6万
查看次数

多行字符串文字的语法是什么?

我很难弄清楚Rust中的字符串语法是如何工作的.具体来说,我试图找出如何制作多行字符串.

string rust

95
推荐指数
5
解决办法
3万
查看次数

如何在Rust中连接静态字符串

我正在尝试连接静态字符串和字符串文字以构建另一个静态字符串.以下是我能想到的最好的,但它不起作用:

const DESCRIPTION: &'static str = "my program";
const VERSION: &'static str = env!("CARGO_PKG_VERSION");
const VERSION_STRING: &'static str = concat!(DESCRIPTION, " v", VERSION);
Run Code Online (Sandbox Code Playgroud)

在Rust中有没有办法做到这一点,或者我必须一遍又一遍地写相同的文字?

rust

14
推荐指数
2
解决办法
3069
查看次数

运行时构建:在此范围内找不到字符串

基板开发人员可能会遇到的一个常见问题是:开发自定义托盘以将映射存储到具有常见类型的存储中,例如String. 举个例子:

#[derive(Encode, Decode, Clone, Default, RuntimeDebug)]
pub struct ClusterMetadata {
    ip_address: String,
    namespace: String,
    whitelisted_ips: String,
}
Run Code Online (Sandbox Code Playgroud)

在构建运行时,您会收到每个错误String

     |
  21 |     ip_address: String,
     |                 ^^^^^^ not found in this scope
Run Code Online (Sandbox Code Playgroud)

为什么Strings不包括在范围内?和其他std锈类型?

string rust substrate rust-no-std

6
推荐指数
1
解决办法
665
查看次数

将字符串文字与另一个字符串连接起来

我有什么理由不能将字符串文字与字符串变量连接起来吗?以下代码:

fn main() {
    let x = ~"abcd";
    io::println("Message: " + x);
}
Run Code Online (Sandbox Code Playgroud)

给出了这个错误:

test2.rs:3:16: 3:31 error: binary operation + cannot be applied to type `&'static str`
test2.rs:3     io::println("Message: " + x);
                           ^~~~~~~~~~~~~~~
error: aborting due to previous error
Run Code Online (Sandbox Code Playgroud)

我想这是一个非常基本且非常常见的模式,fmt!在这种情况下的使用只会带来不必要的混乱.

string concatenation rust

4
推荐指数
2
解决办法
5431
查看次数