Skip to content

Instantly share code, notes, and snippets.

@MarkJr94
Created August 6, 2013 20:30
Show Gist options
  • Save MarkJr94/6168319 to your computer and use it in GitHub Desktop.
Save MarkJr94/6168319 to your computer and use it in GitHub Desktop.
Weird lifetime issue
md_ref = line.split_iter(' ')
.transform(|s| s.to_owned())
.collect::<~[~str]>()[2]
.iter()
.collect::<~[char]>()
.chunk_iter(2)
.transform(|cs| {
let s = str::from_chars(cs);
println(s);
u8::from_str_radix(s, 16).get()
})
.collect();
// Error
nist.rs:117:29: 122:25 error: borrowed value does not live long enough
nist.rs:117 md_ref = line.split_iter(' ')
nist.rs:118 .transform(|s| s.to_owned())
nist.rs:119 .collect::<~[~str]>()[2]
nist.rs:120 .iter()
nist.rs:121 .collect::<~[char]>()
nist.rs:122 .chunk_iter(2)
nist.rs:117:29: 128:35 note: borrowed pointer must be valid for the method call at 117:29...
nist.rs:117 md_ref = line.split_iter(' ')
nist.rs:118 .transform(|s| s.to_owned())
nist.rs:119 .collect::<~[~str]>()[2]
nist.rs:120 .iter()
nist.rs:121 .collect::<~[char]>()
nist.rs:122 .chunk_iter(2)
...
nist.rs:117:29: 123:25 note: ...but borrowed value is only valid for the method call at 117:29
nist.rs:117 md_ref = line.split_iter(' ')
nist.rs:118 .transform(|s| s.to_owned())
nist.rs:119 .collect::<~[~str]>()[2]
nist.rs:120 .iter()
nist.rs:121 .collect::<~[char]>()
nist.rs:122 .chunk_iter(2)
...
nist.rs:117:29: 119:47 error: borrowed value does not live long enough
nist.rs:117 md_ref = line.split_iter(' ')
nist.rs:118 .transform(|s| s.to_owned())
nist.rs:119 .collect::<~[~str]>()[2]
nist.rs:117:29: 122:25 note: borrowed pointer must be valid for the method call at 117:29...
nist.rs:117 md_ref = line.split_iter(' ')
nist.rs:118 .transform(|s| s.to_owned())
nist.rs:119 .collect::<~[~str]>()[2]
nist.rs:120 .iter()
nist.rs:121 .collect::<~[char]>()
nist.rs:122 .chunk_iter(2)
nist.rs:117:29: 121:25 note: ...but borrowed value is only valid for the method call at 117:29
nist.rs:117 md_ref = line.split_iter(' ')
nist.rs:118 .transform(|s| s.to_owned())
nist.rs:119 .collect::<~[~str]>()[2]
nist.rs:120 .iter()
nist.rs:121 .collect::<~[char]>()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment