The parameter ln
doesn't live long enough, and I couldn't seem to find a reason why it does. I tried to make it and the value I was giving it as input static, but that just caused other problems.
pub fn CompileLine(ln: &str) -> std::vec::Vec<u8> {
let mut out = std::vec::Vec::new();
let splitLn: Vec<&str> = ln.split_whitespace().collect();
match splitLn[0] {
"exit" => out.push(0),
"reg" => out.push(0x1),
"rem" => out.push(0x2),
"set" => out.push(0x3),
"sum" => out.push(0x4),
"jmp" => out.push(0x5),
_ => panic!(splitLn[0]),
}
return out;
}
error[E0495]: cannot infer an appropriate lifetime for autoref due to conflicting requirements
--> src/main.rs:3:33
|
3 | let splitLn: Vec<&str> = ln.split_whitespace().collect();
| ^^^^^^^^^^^^^^^^
|
note: first, the lifetime cannot outlive the anonymous lifetime #1 defined on the function body at 1:1...
--> src/main.rs:1:1
|
1 | / pub fn CompileLine(ln: &str) -> std::vec::Vec<u8> {
2 | | let mut out = std::vec::Vec::new();
3 | | let splitLn: Vec<&str> = ln.split_whitespace().collect();
4 | | match splitLn[0] {
... |
13| | return out;
14| | }
| |_^
note: ...so that reference does not outlive borrowed content
--> src/main.rs:3:30
|
3 | let splitLn: Vec<&str> = ln.split_whitespace().collect();
| ^^
= note: but, the lifetime must be valid for the static lifetime...
note: ...so that the type `&str` will meet its required lifetime bounds
--> src/main.rs:11:14
|
11| _ => panic!(splitLn[0]),
| ^^^^^^^^^^^^^^^^^^
= note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)