Created
February 21, 2018 22:48
-
-
Save opensourcegeek/59292253dd06364dd06d82ade0aa51ef to your computer and use it in GitHub Desktop.
Lifetime issue with bufwriter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extern crate ssh2; | |
use std::net::TcpStream; | |
use std::path::Path; | |
use std::io::BufWriter; | |
use ssh2::Session; | |
use ssh2::{OpenType, WRITE, TRUNCATE}; | |
fn create_session<'a>() -> (TcpStream, Session, BufWriter<ssh2::File<'a>>) { | |
let tcp = TcpStream::connect("test:22").expect("Cannot connect"); | |
let mut sess = Session::new().expect("cannot start session"); | |
sess.handshake(&tcp).expect("handshake failed"); | |
sess.userauth_password("test", "boo").expect("Cannot authenticate"); | |
assert!(sess.authenticated()); | |
let sftp = sess.sftp().expect("Cannot start sftp subsystem"); | |
sftp.create(Path::new("sample.txt")).expect("Cannot create file in target directory"); | |
let f = sftp.open_mode(Path::new("sample.txt"), WRITE | TRUNCATE, 0o644, OpenType::File).expect("Cannot open file file for writing"); | |
let mut buf_file = BufWriter::new(f); | |
(tcp, sess, buf_file) | |
} | |
struct Sample<'b> { | |
// session: Session, | |
// sftp: ssh2::Sftp<'a> | |
buf_file: BufWriter<ssh2::File<'b>> | |
} | |
impl <'b> Sample<'b> { | |
fn new(buf_file: BufWriter<ssh2::File<'b>>) -> Sample<'b> { | |
Sample { | |
// session: s, | |
buf_file | |
} | |
} | |
fn print_some(&self) -> () { | |
println!("Got it!!"); | |
} | |
} | |
fn main() { | |
let (stream, sess, buf_file) = create_session(); | |
let s = Sample::new(buf_file); | |
s.print_some(); | |
} |
Author
opensourcegeek
commented
Feb 21, 2018
•
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment