/// Whereas get_drill allows the caller to store the drill with a strong reference, thus controlling how long it stays in memory,
/// this function only gets a borrow to a drill, thus saving a clone. If the drill is not found, then
/// None will be passed into the supplied function.
pub async fn async_borrow_drill<F: Future>(&self, version: Option<u32>, f: impl FnOnce(Option<&Drill>) -> F) -> F::Output {
let read = self.read().await; // RwLock Read handle
if let Some(version) = version {
f(read.toolset.get_drill(version)).await
} else {
f(read.toolset.get_most_recent_drill()).await
}
}
The above function compiles just fine. When I run the command with this, compilation and execution is also a success:
cnac.async_borrow_drill(Some(51), async move |drill_opt| {
println!("This runs!");
}).await;
This, however, does not compile:
cnac.async_borrow_drill(Some(51), async move |drill_opt| {
if let Some(drill) = drill_opt {
println!("Borrowing drill vers: {}", drill.get_version());
}
}).await;
The error is:
error[E0495]: cannot infer an appropriate lifetime due to conflicting requirements
--> hyxe_user\tests\primary.rs:102:82
|
102 | cnac.async_borrow_drill(Some(51), async move |drill_opt| {
| __________________________________________________________________________________^
103 | | if let Some(drill) = drill_opt {
104 | | println!("Borrowing drill vers: {}", drill.get_version());
105 | | }
106 | | }).await;
| |_________________________^
|
note: first, the lifetime cannot outlive the anonymous lifetime #2 defined on the body at 102:59...
--> hyxe_user\tests\primary.rs:102:59
|
102 | cnac.async_borrow_drill(Some(51), async move |drill_opt| {
| ___________________________________________________________^
103 | | if let Some(drill) = drill_opt {
104 | | println!("Borrowing drill vers: {}", drill.get_version());
105 | | }
106 | | }).await;
| |_________________________^
note: ...so that the types are compatible
--> hyxe_user\tests\primary.rs:102:82
|
102 | cnac.async_borrow_drill(Some(51), async move |drill_opt| {
| __________________________________________________________________________________^
103 | | if let Some(drill) = drill_opt {
104 | | println!("Borrowing drill vers: {}", drill.get_version());
105 | | }
106 | | }).await;
| |_________________________^
= note: expected `std::option::Option<&hyxe_crypt::drill::Drill>`
found `std::option::Option<&hyxe_crypt::drill::Drill>`
note: but, the lifetime must be valid for the method call at 102:25...
--> hyxe_user\tests\primary.rs:102:25
|
102 | / cnac.async_borrow_drill(Some(51), async move |drill_opt| {
103 | | if let Some(drill) = drill_opt {
104 | |
println!("Borrowing drill vers: {}", drill.get_version());
105 | | }
106 | | }).await;
| |__________________________^
note: ...so type `impl core::future::future::Future` of expression is valid during the expression
--> hyxe_user\tests\primary.rs:102:25
|
102 | / cnac.async_borrow_drill(Some(51), async move |drill_opt| {
103 | | if let Some(drill) = drill_opt {
104 | | println!("Borrowing drill vers: {}", drill.get_version());
105 | | }
106 | | }).await;
| |__________________________^