引用必须对50:74处的块有效... ...但是借用值仅对50:74处的块有效
好的,那么问题出在哪里呢?
涉及到的块为:
pub fn git_upload_pack(self: &mut GitConnect) -> Result<String, &str> {
let c = format!("git-upload-pack {}\0host={}\0", self.repo.path, self.repo.domain);
let mut out = String::new();
let data = try!(self.command(c.as_slice()));
for line in data.iter() {
out.push_str(from_utf8(line.as_slice()).unwrap());
}
Ok(out)
}
self.command
:
fn command(self: &mut GitConnect, command: &str) -> Result<Vec<Vec<u8>>, &str> {
完整的错误信息如下:
src/protocol/git_connect.rs:54:38: 54:39 error: `c` does not live long enough
src/protocol/git_connect.rs:54 let data = try!(self.command(c.as_slice()));
^
<std macros>:1:1: 6:60 note: in expansion of try!
src/protocol/git_connect.rs:54:20: 54:53 note: expansion site
src/protocol/git_connect.rs:50:75: 61:6 note: reference must be valid for the anonymous lifetime #1 defined on the block at 50:74...
src/protocol/git_connect.rs:50 pub fn git_upload_pack(self: &mut GitConnect) -> Result<String, &str> {
src/protocol/git_connect.rs:51 let c = format!("git-upload-pack {}\0host={}\0", self.repo.path, self.repo.domain);
src/protocol/git_connect.rs:52
src/protocol/git_connect.rs:53 let mut out = String::new();
src/protocol/git_connect.rs:54 let data = try!(self.command(c.as_slice()));
src/protocol/git_connect.rs:55
...
src/protocol/git_connect.rs:50:75: 61:6 note: ...but borrowed value is only valid for the block at 50:74
src/protocol/git_connect.rs:50 pub fn git_upload_pack(self: &mut GitConnect) -> Result<String, &str> {
src/protocol/git_connect.rs:51 let c = format!("git-upload-pack {}\0host={}\0", self.repo.path, self.repo.domain);
src/protocol/git_connect.rs:52
src/protocol/git_connect.rs:53 let mut out = String::new();
src/protocol/git_connect.rs:54 let data = try!(self.command(c.as_slice()));
self.command
的签名是什么? - Vladimir Matveev