Is my chaser drunk?

the link must be valid for the block at 50:74 ...... but the borrowed value is valid only for the block at 50:74

Right So what is the problem?

This block:

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> {

Full error:

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()));
+4
source share
1 answer

This seems like a mistake.

This signature:

fn command(self: &mut GitConnect, command: &str) -> Result<Vec<Vec<u8>>, &str>

in accordance with the rules of the life cycle , should be equivalent to this:

fn command<'a, 'b>(self: &'a mut GitConnect, command: &'b str) -> Result<Vec<Vec<u8>>, &'a str>

And in fact, if you rewrite your own command()to use this advanced option, it should compile. Also, if you use an abbreviated definition of the argument self:

fn command(&mut self, command: &str) -> Result<Vec<Vec<u8>>, &str>

then it also compiles.

It seems that now

fn command(self: &mut GitConnect, command: &str) -> Result<Vec<Vec<u8>>, &str>

equivalently

fn command<'a>(self: &'a mut GitConnect, command: &'a str) -> Result<Vec<Vec<u8>>, &'a str>

​​ , : command , self, , self.

+3

All Articles