This code, with rust 1.72.1 (the latest available to me until I upgrade my OpenBSD laptop):
fn add_uri_entity_with_uri_attribute<'a>(
&'a self,
transaction: Option<Rc<RefCell<Transaction<'a, Postgres>>>>,
[....]
quote_in: Option<&str>, /*= None*/
) -> Result<(Entity<'a>, RelationToLocalEntity<'a>), anyhow::Error> {
[....]
let (new_entity, new_rtle) = containing_entity_in
.create_entity_and_add_has_local_relation_to_it(
transaction.clone(),
new_entity_name_in,
observation_date_in,
make_them_public_in,
caller_manages_transactions_in,
)?;
[....]
let new_entity2 = new_entity.clone();
new_entity2.add_text_attribute2(
transaction.clone(),
uri_class_template_id,
uri_in,
None,
None,
observation_date_in,
caller_manages_transactions_in,
)?;
Ok((new_entity, new_rtle))
}
...gets this error:
error[E0597]: `new_entity2` does not live long enough
--> src/model/postgres/postgresql_database3.rs:106:9
|
43 | fn add_uri_entity_with_uri_attribute<'a>(
| -- lifetime `'a` defined here
...
96 | let new_entity2 = new_entity.clone();
| ----------- binding `new_entity2` declared here
...
106 | / new_entity2.add_text_attribute2(
107 | | transaction.clone(),
108 | | uri_class_template_id,
109 | | uri_in,
... |
113 | | caller_manages_transactions_in,
114 | | )?;
| | ^
| | |
| |_________borrowed value does not live long enough
| argument requires that `new_entity2` is borrowed for `'a`
...
126 | }
| - `new_entity2` dropped here while still borrowed
For more information about this error, try `rustc --explain E0597`.
error: could not compile `onemodel` (bin "onemodel" test) due to previous error
5.48 real 3.30 user 0.74 sys
...which I fail to understand. I don’t get why it thinks the value has been borrowed, or how to fix it. The current code reflects some of the things I have tried so far. I have been studying about lifetimes but am not sure that my program is using them correctly in general -- I have been mostly just following the advice of the compiler -- I’m not sure if I could somehow specify fewer lifetimes in general, in the program as a whole.
The entire program is here, with this error around line 99 of:
...and the method being called is here:
...where the last commit to the project contains this error. The code is in a state of flux, incrementally converting from commented-out Scala into Rust.
Thanks much!!