I have a find
function defined on a basic in-memory storage solution. I'm trying to find a way to flexibly pass conditional search options by creating a struct
called 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
I don't know if this is the best way to implement this sort of functionality, but I also don't understand how to please the borrow checker in this instance (which is the thing I'd like to learn first).