Skip to content

Add .reborrow() methods to array views #412

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 26, 2018
Merged

Add .reborrow() methods to array views #412

merged 1 commit into from
Jan 26, 2018

Conversation

bluss
Copy link
Member

@bluss bluss commented Jan 25, 2018

ArrayView<'a, T, D> is invariant in parameters T and 'a, because
ArrayBase<S, D> is invariant in the parameter S because the array
base is using the projection <S as Data>::Elem in the struct
definition.

This means that the equivalent of the &'a T -> &'b T conversion (valid
whenever 'a: 'b is not naturally available for array views; we can
provide it manually, with a method.

`ArrayView<'a, T, D>` is invariant in parameters `T` and `'a`, because
`ArrayBase<S, D>` is invariant in the parameter `S` because the array
base is using the projection `<S as Data>::Elem` in the struct
definition.

This means that the equivalent of the `&'a T -> &'b T` conversion (valid
whenever `'a: 'b` is not naturally available for array views; we can
provide it manually, with a method.
@bluss
Copy link
Member Author

bluss commented Jan 25, 2018

cc @jturner314; I'm unsure here if "reborrow" is the right name.

@jturner314
Copy link
Member

"reborrow" seems like a good name to me. You are effectively borrowing the data again; the 'a: 'b constraint is just necessary to ensure that the lifetime of the new borrow is valid. You could call it "shrink_lifetime", "reduce_lifetime", or "shorten_life", but I like "reborrow" better.

For those not on IRC, this was the case that caused me to encounter the issue. I did find that calling .view() on state (Foo { mean: state.view(), covariance: view }) was a workaround for this particular case, but I'm not sure that workaround would work for all cases.

@Robbepop
Copy link

I was really in need of this API some time ago. Thanks for introducing it! :)

@bluss bluss merged commit 8218867 into master Jan 26, 2018
@bluss
Copy link
Member Author

bluss commented Jan 26, 2018

Good. It is a temporary solution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants