【发布时间】:2021-06-12 17:25:48
【问题描述】:
我有一个大对象,我需要将它装在另一个对象中,但我不一定总是需要它。所以我想使用 if 语句来获取可选的盒装 TempStructure,但我不确定如何同时解构和取消引用。
例子:
pub struct TempStructure {
lots_of_data: [u64; 64],
}
pub struct Structure {
pending_removal: Option<Box<(TempStructure, bool)>>,
}
impl Structure {
pub fn do_somthing(&mut self) {
// How do I destructure the Option and dereference the Box to get TempStructure?
if let Some((temp_structure, some_boolean)) = self.pending_removal.take() {
// Do something with temp_structure and some_boolean
}
}
}
当我这样做时 ^^^ 我收到 expected struct `std::boxed::Box`, found tuple 错误。
【问题讨论】:
标签: rust dereference destructuring