Skip to content

Instantly share code, notes, and snippets.

@andoriyu
Last active June 20, 2017 23:16
Show Gist options
  • Save andoriyu/6936f0031d965908fa8b8c48833c62a1 to your computer and use it in GitHub Desktop.
Save andoriyu/6936f0031d965908fa8b8c48833c62a1 to your computer and use it in GitHub Desktop.
@ac-book.local  4:15PM  ~/Dev/Heaven/angel-whisper   master ● 
$  cargo check
Compiling angel_whisper v0.1.0 (file:///Users/andoriyu/Dev/Heaven/angel-whisper)
error[E0597]: `service` does not live long enough
--> src/llsd/tokio.rs:98:9
|
97 | service.borrow().call(initiate).and_then(move |_| ok(()))
| ------- borrow occurs here
98 | });
| ^ `service` dropped here while still borrowed
|
= note: values in a scope are dropped in the opposite order they are created
error: aborting due to previous error(s)
error: Could not compile `angel_whisper`.
To learn more, run the command again with --verbose.
use futures::future::{ok,err, Future};
use std::cell::RefCell;
use std::rc::Rc;
use llsd::session::client::Session as ClientSession;
use tokio_proto::pipeline::ClientService;
use tokio_core::net::TcpStream;
use tokio_service::Service;
pub trait ClientExt {
fn service(&self) -> Rc<RefCell<ClientService<TcpStream, WhisperPipelinedProtocol>>>;
fn session(&self) -> Rc<RefCell<ClientSession>>;
fn authenticate(&self) -> Box<Future<Item = (), Error = io::Error>> {
let session = self.session().clone();
let service = self.service().clone();
let hello_frame = session.borrow().make_hello();
let hello_future = service.borrow().call(hello_frame);
let ret = hello_future.and_then(move |hello_resp| {
let initiate = session.borrow_mut().make_initiate(&hello_resp).unwrap();
service.borrow().call(initiate).and_then(move |_| ok(()))
});
Box::new(ret)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment