-
Notifications
You must be signed in to change notification settings - Fork 308
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
ArrayView
should be covariant over lifetime
#1332
Comments
Does the method reborrow help in your case? https://docs.rs/ndarray/latest/ndarray/type.ArrayView.html#method.reborrow |
No sadly it does not. The functions in the code work on references to the complete data structure, and therefore using reborrow would require to duplicate the complete data structure. |
Edit: After looking at it, this is probably related to #1341 I have minimized it to this snippet: If either the fn x<'s>(x: &'s ArrayBase<OwnedRepr<&'s str>>) {
()
}
pub struct ArrayBase<S>
where
S: MyTrait, {
pub data: S,
pub ptr: <S as MyTrait>::Elem,
}
trait MyTrait {
type Elem;
}
pub struct OwnedRepr<A>(A);
impl<A> Drop for OwnedRepr<A> {
fn drop(&mut self) {
todo!()
}
}
impl<T> MyTrait for OwnedRepr<T> {
type Elem = T;
}
fn main() {
let elem = "abc";
let data = OwnedRepr(elem);
let input = ArrayBase {
data,
ptr: elem
};
x(&input);
} |
put this in order after implementing ArrayRef #879, probably not going to be possible though (?) without new Rust features. |
Take a look at the following example:
The first compiles fine, the second one does not compile and give the following error message:
The problem is caused by the usage of
S::Elem
inside the definition ofArrayBase
.I stumbled across this problem, since I used
ArrayView
deep inside a data structure which should be covariant.As a user of ndarray I would assume that
ArrayView
s behave the same as Rust references, but I see fixing this bug is hard without interface changes.Is there an easy work-around for such problems? I currently do not know of any...
The text was updated successfully, but these errors were encountered: