fnmain(){letr;{lets="hello world".to_owned();r=&s;}println!("{}",r);} 报的错误为s does not live long enough error[E0597]: `s` does not live long enough --> test.rs:5:14 | 5 | r = &s; | ^^ borrowed value does not live long enough 6 | } | - `s` dropped here...
执行的时候会报出如下错误:borrowed value does not live long enough,意思就是借用的值存活的时间不够长。因为把 x 的引用给 r 之后,x 就被销毁了,那么 r 就成为了一个悬空引用。 而Rust 会通过借用检查器,来检查借用是否合法,显然上述代码在执行打印语句的时候,r 已经不合法了。 fnlongest(x: &str, y:...
Vec<(&str, &str)>>。这意味着如果parse_multiline()失败,则返回nom::Err<nom::error::Error<&...
fnmain(){letstring1=String::from("long string is long");letresult;{letstring2=String::from("xyz");result=longest(string1.as_str(),string2.as_str());}println!("The longest string is {}",result);} img_error_borrowed_value_does_not_live_long_enough 我们把result放到main这个作用域中,...
509证书的生命周期将绑定到这些缓冲区。一个解决方案是将pems持久化在一个单独的列表中。类似于这样:
| ^^ borrowed value does not live long enough 6 | }; | - `b` dropped here while still borrowed 7 | println!("a:{}", a); | - borrow later used here 1. 2. 3. 4. 5. 6. 7. 8. 9. 意思就是说变量b的生命周期不够长。变量b已经被销毁了仍然对它进行了借用。
首先你在main方法中创建ivec,它的生命周期是'main函数周围的括号。
// ^^ borrowed value does not live long enough } // - `x` dropped here while still borrowed println!("r: {}", r); // - borrow later used here } } 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. let r; 声明了一个变量,在内层语句块中变成对 x 变量的...
509证书的生命周期将绑定到这些缓冲区。一个解决方案是将pems持久化在一个单独的列表中。类似于这样:
assert_eq!(has.lifetime, "long"); } 报错: error[E0597]: `short` does not live long enough --> src/main.rs:11:24 | 11 | has.lifetime = &short; | ^^^ borrowed value does not live long enough ... 15 | } | - `short` dropped here while still borrowed 16 |...