我有一个函数,该函数在三个引用字段中的结构中存储两个参数。我不知道如何指定此第三个结果字段的生存期,这是该函数的前两个参数的生存期的组合。
我尝试将前两个参考参数存储在结构中。这工作得很好,没有意义。我在下面显示的情况更有趣,我没有解决方案。
我知道这段代码没有任何意义;它只是显示问题。
// This function can be found in "Lifetime Annotations in Function Signatures" of the Rust manual
fn longest<'a>(x: &'a str, y: &'a str) -> &'a str {
if x.len() > y.len() {
x
} else {
y
}
}
// Here comes the interesting part; 1st the result type of my function
struct SillyResult<'a, 'b, 'c> {
arg1: &'a str,
arg2: &'b str,
result: &'c str,
}
// ... and now the function, that does not compile …Run Code Online (Sandbox Code Playgroud)