如何将值推送到Rust中枚举 struct 中的vec?
我正在try 弄清楚如何将值推送到定义为 struct 的枚举内的vec.
以下是我try 过的一些设置:
enum Widget {
Alfa { strings: Vec<String> },
}
fn main() {
let wa = Widget::Alfa { strings: vec![] };
// wa.strings.push("a".to_string());
// no field `strings` on type `Widget`
// wa.Alfa.strings.push("a".to_string());
// no field `Alfa` on type `Widget`
// wa.alfa.strings.push("a".to_string());
// no field `alfa` on type `Widget`
// wa.Widget::Alfa.strings.push("a".to_string());
// expected one of `(`, `.`, `;`, `?`, `}`, or an operator, found `::`
// wa["strings"].push("a".to_string());
// cannot index into a value of type `Widget`
}
是否可以在eMum中创建VEC后对其进行更新?如果是这样的话,我们该如何go 做呢?