Getting a slice out of an ArrayView: cannot return value referencing function parameter

Đang mở
#621 5 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Đánh giá

Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
25/100
Loại issue
Lỗi
Độ rõ ràng
Cần làm rõ
Mức độ hoạt động
Đình trệ
Công nghệ
rust
Lĩnh vực
data

Hướng nghiên cứu

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.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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?

Ngôn ngữ chính
Rust
Star
4.3k
Fork
391
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Hướng dẫn đóng góp

Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của rust-ndarray/ndarray

Tất cả issue của rust-ndarray/ndarray

Issue tương tự

Thêm issue về Rust

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.