If anyone can help me I'm tearing my hair out (and there isn't much of it left!!)
I have a method (below) and the borrow checker complains that the borrow at self.sync_databases.iter()
overlaps the one at self.sync_databases.push(..)
, but in my mind they don't. Is what I'm trying to do safe? If it is, is there a way to appease the borrow checker (either with or without unsafe
)?
pub fn register_sync_database<'a>(
&'a mut self,
name: impl AsRef<str>,
) -> Result<Db<'a>, Error> {
let name = name.as_ref();
// If we've already registered the database, just return it
if let Some(db) = self.sync_databases.iter().find(|&db| db.name() == name) {
warn!(r#"database "{}" already registered"#, name);
return Ok(Db::new(db, self));
}
let base = DbBase::new_sync(name, self, SignatureLevel::default())?;
let db_idx = self.sync_databases.len();
self.sync_databases.push(base);
Ok(Db::new(&self.sync_databases[db_idx], self))
}
EDIT worth mentioning that I've already tried extra braces around the if let
.
EDIT2 it works with nll
! Which suggests what I'm trying to do is safe if nll is working