Title: Lifetime troubles · Issue #1341 · rust-ndarray/ndarray · GitHub
Open Graph Title: Lifetime troubles · Issue #1341 · rust-ndarray/ndarray
X Title: Lifetime troubles · Issue #1341 · rust-ndarray/ndarray
Description: Hi! I've been stuck on an issue for a while and can't figure out what's causing it. Not sure if there's an issue in ndarray, Rust or if I'm just missing something. Playground I'm trying to create a struct containing a list of arrays, whe...
Open Graph Description: Hi! I've been stuck on an issue for a while and can't figure out what's causing it. Not sure if there's an issue in ndarray, Rust or if I'm just missing something. Playground I'm trying to create a...
X Description: Hi! I've been stuck on an issue for a while and can't figure out what's causing it. Not sure if there's an issue in ndarray, Rust or if I'm just missing something. Playground I&...
Opengraph URL: https://github.com/rust-ndarray/ndarray/issues/1341
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Lifetime troubles","articleBody":"Hi! I've been stuck on an issue for a while and can't figure out what's causing it. Not sure if there's an issue in ndarray, Rust or if I'm just missing something.\r\n\r\n[Playground](https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=d18ceea0daf456711b5354e9fe294b96)\r\n\r\nI'm trying to create a struct containing a list of arrays, where the array elements are string slices:\r\n\r\n```rust\r\nstruct ListOfArrays\u003c'a, D: ndarray::Dimension> {\r\n data: &'a [ndarray::Array\u003c&'a str, D>],\r\n}\r\n\r\nfn does_not_work() {\r\n let arrays = [ndarray::array![\"\"]];\r\n let list = ListOfArrays { data: &arrays };\r\n}\r\n// Error: `arrays` does not live long enough\r\n// borrowed value does not live long enough. \r\n// `arrays` dropped here while still borrowed\r\n```\r\n\r\nThing is, this same thing is totally doable with other Rust structs, for example if we replace ndarray with Vec:\r\n\r\n```rust\r\nstruct ListOfArraysVec\u003c'a> {\r\n data: &'a [Vec\u003c&'a str>],\r\n}\r\n\r\nfn works() {\r\n let arrays = [vec![\"\"]];\r\n let list = ListOfArrays { data: &arrays };\r\n}\r\n// Compiles!\r\n```\r\n\r\nI don't understand why this happens with ndarray, and I haven't been successful in recreating the issue with any struct other than ndarray, so that is why I'm posting here. Any guidance would be much appreciated!","author":{"url":"https://github.com/ViktorWb","@type":"Person","name":"ViktorWb"},"datePublished":"2023-12-12T23:12:27Z","url":"https://github.com/rust-ndarray/ndarray/issues/1341"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:31f0ed79-fc74-0178-06d3-5d75783a35f2 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | C47C:7D71:1A9AA1:247569:6AFD5F36 |
| html-safe-nonce | 28a639bf063900a7fe70629c686a7846a61e6e428004c6028ff04c252eaf3dba |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDNDdDOjdENzE6MUE5QUExOjI0NzU2OTo2QUZENUYzNiIsInZpc2l0b3JfaWQiOiIyNjM3ODM2MTY2MTQ5MDA1MTEwIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | d104b1579d70abb864a522076f5bf9eb4dcf5cfb939b9d22ecfcdbe02a850dd7 |
| hovercard-subject-tag | issue:2038686453 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/rust-ndarray/ndarray/1341/issue_layout |
| twitter:image | https://opengraph.githubassets.com/74e7ebf9cb8d0c2d0459dcb4f72c7d3ef7c1553206f22d5f8a35ff96a2d080f1/rust-ndarray/ndarray/issues/1341 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/74e7ebf9cb8d0c2d0459dcb4f72c7d3ef7c1553206f22d5f8a35ff96a2d080f1/rust-ndarray/ndarray/issues/1341 |
| og:image:alt | Hi! I've been stuck on an issue for a while and can't figure out what's causing it. Not sure if there's an issue in ndarray, Rust or if I'm just missing something. Playground I'm trying to create a... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | ViktorWb |
| hostname | github.com |
| expected-hostname | github.com |
| None | 66653c2e55a6fff2930be1bdf07ee4f8aa137e3956d056c822563be6f878755e |
| turbo-cache-control | no-preview |
| go-import | github.com/rust-ndarray/ndarray git https://github.com/rust-ndarray/ndarray.git |
| octolytics-dimension-user_id | 44419403 |
| octolytics-dimension-user_login | rust-ndarray |
| octolytics-dimension-repository_id | 22598813 |
| octolytics-dimension-repository_nwo | rust-ndarray/ndarray |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 22598813 |
| octolytics-dimension-repository_network_root_nwo | rust-ndarray/ndarray |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | b6f01f7cb9f35f8c09949773241a3d49dd04b340 |
| ui-target | canary-2 |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width