我find
在基本的内存存储解决方案上定义了一个函数。我试图通过创建一个struct
被调用的方法来灵活地传递条件搜索选项SearchOpts
:
trait HasRecords {
fn find(&self, opts: &SearchOpts) -> ();
}
pub struct SearchOpts {
sensorId: Option<String>,
}
struct MemDb {
id: u32,
}
impl HasRecords for MemDb {
fn find(&self, opts: &SearchOpts) -> () {
println!("Hello {}", opts.sensorId.unwrap());
}
}
fn main() {
let _x = MemDb { id: 42 };
}
error[E0507]: cannot move out of borrowed content
--> src/main.rs:15:30
|
15 | println!("Hello {}", opts.sensorId.unwrap());
| ^^^^ cannot move out of borrowed content
我不知道这是否是实现此类功能的最佳方式,但我也不明白在这种情况下如何取悦借用检查器(这是我想首先学习的东西)。