Skip to content

Instantly share code, notes, and snippets.

@jamwt
Last active August 29, 2015 14:12
Show Gist options
  • Save jamwt/c77389b89aa54d42f886 to your computer and use it in GitHub Desktop.
Save jamwt/c77389b89aa54d42f886 to your computer and use it in GitHub Desktop.
impl<'a, C: 'a + AbstractConnection + Send> ConnPool<'a, C> {
pub fn borrow(&'a self) -> Result<ScopedConn<C>, IoError> {
// With pool-wide lock, pick a host.
let host_pool: Arc<HostPool<'a, C>> = try!({
let mut pool = self.pool.lock();
pool.pick_host().clone()
});
// Acquire connection with narrower locking.
host_pool.lease(self.max_idle_conns, &self.make_conn)
}
}
@jamwt
Copy link
Author

jamwt commented Dec 29, 2014

$ cargo build
   Compiling stuff v0.0.1 (file:///home/jamwt/devel/rust-server)
/home/jamwt/devel/rust-server/src/util/connpool.rs:144:38: 144:44 error: declared lifetime bound not satisfied
/home/jamwt/devel/rust-server/src/util/connpool.rs:144             let mut pool = self.pool.lock();
                                                                                        ^~~~~~
/home/jamwt/devel/rust-server/src/util/connpool.rs:141:63: 149:6 note: lifetime parameter instantiated with the lifetime 'a as defined on the block at 141:62
/home/jamwt/devel/rust-server/src/util/connpool.rs:141     pub fn borrow(&'a self) -> Result<ScopedConn<C>, IoError> {
/home/jamwt/devel/rust-server/src/util/connpool.rs:142         // With pool-wide lock, pick a host.
/home/jamwt/devel/rust-server/src/util/connpool.rs:143         let host_pool: Arc<HostPool<'a, C>> = try!({
/home/jamwt/devel/rust-server/src/util/connpool.rs:144             let mut pool = self.pool.lock();
/home/jamwt/devel/rust-server/src/util/connpool.rs:145             pool.pick_host().clone()
/home/jamwt/devel/rust-server/src/util/connpool.rs:146         });
                                                       ...
note: but lifetime parameter must outlive the static lifetime
error: aborting due to previous error
Could not compile `stuff`.

To learn more, run the command again with --verbose.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment