我有一个类型为Vec<Candle>
的,需要取得它的最后一个元素,并尝试使用unwrap_or_default
方法:
self.candle_series.last().unwrap_or_default()
但是我收到了这个错误:
method not found in `std::option::Option<&market::Candle>
如何在结构体上获得 unwrap_or_default
的行为而不是在引用上?
我的当前解决方法如下,但似乎不正确。如果它是正确的,请告诉我:
self.candle_series.last().unwrap_or(&Candle::default())