Skip to content

Returning PyArray from struct #393

Closed Answered by adamreichold
realiti4 asked this question in Q&A
Discussion options

You must be logged in to vote

Ah yes, for methods, the inferred lifetime is always that attached to the &self reference, so you have to make the lifetime explicit, i.e.

fn my_array<'py>(&self, py: Python<'py>) -> &'py PyArray1<f64> {
    self.data.to_pyarray(py)
}

(The inferred version would have been

fn my_array<'a, 'b>(&'a self, py: Python<'b>) -> &'a PyArray1<f64> {
    self.data.to_pyarray(py)
}

which does not work as you describe.)

Replies: 1 comment 5 replies

Comment options

You must be logged in to vote
5 replies
@realiti4
Comment options

@adamreichold
Comment options

@realiti4
Comment options

@adamreichold
Comment options

Answer selected by realiti4
@realiti4
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #392 on September 25, 2023 19:51.