English 中文(简体)
1. 终身陪产假: 1
原标题:Lifetime Compiler notations: 1 vs 2
  • 时间:2024-01-01 02:43:08
  •  标签:
  • rust

在以下Rust汇编者错误中,预期类型与发现类型之间的唯一区别是,有两种寿命,即: 1 2, 预期,且其发现类型相同, 1 1。 汇编者试图说什么? 如果两生的执行必须相同,则汇编者可以接受<代码> 1为 2

`impl` item signature doesn t match `trait` item signature
expected signature `fn(& 1 ArrayBase<OwnedRepr<f64>, Dim<[usize; 2]>>) -> std::iter::Map<ndarray::iter::Iter< 2, f64, Dim<[usize; 2]>>, fn(& cellref f64) -> & cellref CellValue< cell>>`
   found signature `fn(& 1 ArrayBase<OwnedRepr<f64>, Dim<[usize; 2]>>) -> std::iter::Map<ndarray::iter::Iter< 1, f64, Dim<[usize; 2]>>, fn(& cellref f64) -> & cellref CellValue< cell>>`

What is the compiler trying to tell you?

问题回答

这只是错误信息的一部分。 通常,该错误的其余部分有说明,解释其意思的是<代码> 1和 2

In any case, the compiler expects your fn type to return an object with the lifetime 2 but you re giving it an object with a lifetime 1 (which was the reference that was passed in). Usually this means that 2 is a longer lifetime than 1 though it can also mean they are completely unrelated lifetimes or potentially that 1 could live long enough but its used in a type that considers it invariant and thus the compiler is not allowed to satisfy 2.

因此,无论你如何通过<代码>fn。 期望这一功能的类型是,根据投入参考,将寿命(或至少不同的寿命)延长的<代码>Iter退回。





相关问题
Creating an alias for a variable

I have the following code in Rust (which will not compile but illustrates what I am after). For readability purposes, I would like to refer the same string with two different names so that the name of ...

Rust Visual Studio Code code completion not working

I m trying to learn Rust and installed the Rust extension for VSCode. But I m not seeing auto-completions for any syntax. I d like to call .trim() on String but I get no completion for it. I read that ...

热门标签