【发布时间】:2018-10-02 18:45:29
【问题描述】:
我正在尝试访问我已实例化的特定clap::App 的版本。但是,version 字段和公共函数 version() 一样存在
以下是相关的源代码:
pub struct App<'a, 'v, 'ab, 'u, 'h, 'ar> {
// ...
version: Option<&'v str>,
// ...
}
impl<'a, 'v, 'ab, 'u, 'h, 'ar> App<'a, 'v, 'ab, 'u, 'h, 'ar>{
// ...
pub fn version(mut self, v: &'v str) -> Self {
self.version = Some(v);
self
}
// ...
}
还有我的代码:
pub fn build_cli() -> App<'static, 'static> {
App::new("my-pi")
.version("0.1.0")
// ...
let app = build_cli();
assert_eq!(app.version, "0.1.0"); // <-- Error here
字段version 和函数version() 都存在于App 上。怎么会这样?以及如何访问字段version?
错误:
error[E0615]: attempted to take value of method `version` on type `clap::App<'_, '_>`
--> src/cli.rs:27:21
|
27 | assert_eq!(app.version, "0.1.0");
| ^^^^^^^
|
= help: maybe a `()` to call it is missing?
【问题讨论】:
标签: rust