首页 > 解决方案 > Rust:连接两个 expr.to_string() 值

问题描述

我该如何解决这个问题?执行是从 process::Command .output() 返回的。

let mut gradinglog = std::str::from_utf8(&execution.stdout).unwrap().to_string() + 
std::str::from_utf8(&execution.stderr).unwrap().to_string();

编译错误日志:

error[E0308]: mismatched types
   --> src/main.rs:270:87
    |
270 | ...rap().to_string() + std::str::from_utf8(&execution.stderr).unwrap().to_string();
    |                                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |                                 |
    |                                 expected `&str`, found struct `std::string::String`
    |                                 help: consider borrowing here: `&std::str::from_utf8(&execution.stderr).unwrap().to_string()`

标签: stringrustcompiler-errorsconcatenation

解决方案


啊,这很奇怪,但是...我设法使用简单的格式进行连接!("{}{}", string1, string2);


推荐阅读