rust - Rust,特征绑定选项未使用 process::Command 定义
问题描述
首先,我知道有一个用于 git 的包,我正在制作一个程序来练习 Rust,我被堆叠起来了。这个想法(从现在开始)是查看当前分支并进行结帐(切换)。正如我所说,不要介意对实际分支进行结帐,并使用 Rust 进行练习。
这是一段代码:
fn get_current_branch() {
let current_branch = Command::new("git")
.arg("rev-parse")
.arg("--abbrev-ref")
.arg("HEAD")
.output()
.expect("Can't retrieve the current branch");
let current: String = String::from_utf8(current_branch.stdout).unwrap().to_string();
Command::new("git")
.arg("checkout")
.arg(current.pop())
.spawn()
.expect("Can't change branch");
}
问题是,在执行此操作时pop()
显示错误:
“特征界限
std::option::Option<char>: std::convert::AsRef<std::ffi::OsStr>
不满足”
我查看了不同的可能答案,但没有任何效果。
感谢您的帮助,♂️。
解决方案
我假设您想使用整个分支,而不仅仅是第一个字符,这pop
将给您。所以,只要使用current
或者current.trim()
如果你想摆脱之后有一个换行符。
推荐阅读
- hyperledger-fabric - 创建 Fabric 网络时如何在我的 Fabric 证书中配置 L、ST、C... 属性?
- python - Python:选择具有更改值的行
- javascript - 使用 JavaScript 的变量中的 TagName 值
- javascript - 为什么 react-native-gifted-chat 不能从 firebase 时间戳正确显示时间?
- javascript - 由于某种原因未执行函数 onsubmit
- sql - 使用 django 出现奇怪的错误:ORA-01843: not a valid month
- c++ - 如何从共享库可移植地导出模板实例
- python - 如何在 Python 中使用生成器比较可迭代对象?
- php - 创建 Jira 问题的 PHP 表单不起作用
- amazon-web-services - 找不到 Golang 的 API 网关映射模板