Getting a slice out of an ArrayView: cannot return value referencing function parameter
还没有人认领这个 Issue。
评估
调研方向
Start with the minimal Rust example and the call at simulate/src/system_serialization.rs:58. Read the ArrayView, as_slice_memory_order, and aview1 definitions to understand the lifetime relationship, then reproduce the compiler error with the reported example. Done means establishing a supported way to construct the one-dimensional view, or documenting why the attempted conversion cannot compile.
由索引模型根据 Issue 内容生成。
描述
I am trying to write a function that interprets an ArrayView as row major order, but Rust doesn't like me extracting the slice underlying the ArrayView. Here is a mimimal example showing the problem:
fn as_standard_view<'a, T>(a: ArrayView<'a, T, Ix2>) -> ArrayView<'a, T, Ix1> {
let slice = a.as_slice_memory_order().unwrap();
aview1(slice)
}
This is the associated error:
error[E0515]: cannot return value referencing function parameter `a`
--> simulate/src/system_serialization.rs:58:5
|
57 | let slice = a.as_slice_memory_order().unwrap();
| - `a` is borrowed here
58 | aview1(slice)
| ^^^^^^^^^^^^^ returns a value referencing data owned by the current function
I do understand the error, but I am not sure how to work around it. After all, the slice is held by the ArrayView, but not the data itself.
Any idea how to construct thay ArrayView without rust thinking that I am trying to reference something inside the function?
- 主要语言
- Rust
- 星标
- 4.3k
- 派生
- 391
- PR 合并指标
- 30 天内没有已合并 PR
贡献指南
这个仓库没有索引到贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
rust-ndarray/ndarray 的其他 Issue
-
难度 2/5 1-3 小时 新手友好度 72/100
rust-ndarray/ndarray#1612 · 1 条评论 ·
-
难度 4/5 3-5 天 新手友好度 48/100
rust-ndarray/ndarray#1617 · 1 条评论 ·
-
bug good first issue
难度 3/5 1-2 天 新手友好度 68/100
rust-ndarray/ndarray#1615 · 1 条评论 ·
-
难度 4/5 3-5 天 新手友好度 48/100
rust-ndarray/ndarray#1610 ·
-
难度 3/5 1-2 天 新手友好度 72/100
rust-ndarray/ndarray#1609 ·
查看 rust-ndarray/ndarray 的全部 Issue
相似的 Issue
-
risk:low runtime status:in-progress type:test
难度 1/5 1 小时以内 新手友好度 92/100
zeroclaw-labs/zeroclaw#11023 ·
-
good first issue refactor
难度 2/5 1-3 小时 新手友好度 72/100
-
难度 2/5 1-3 小时 新手友好度 84/100
EricSpencer00/Resilient#4835 · 1 条评论 ·
-
agent:ready documentation
难度 2/5 1-3 小时 新手友好度 88/100
cesarferreira/stax#890 ·
-
bug
难度 1/5 1 小时以内 新手友好度 90/100