-
Notifications
You must be signed in to change notification settings - Fork 1
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
Add From implementations. #3
Conversation
Thanks for the pull request, and welcome! You should hear from @huonw (or someone else) soon. |
@@ -59,3 +59,18 @@ impl<'a,T> Strided for MutStride<'a,T> { | |||
impl<'a,T> MutStrided for MutStride<'a,T> { | |||
fn as_stride_mut(&mut self) -> MutStride<T> { self.reborrow() } | |||
} | |||
|
|||
// this isn't as general as it could be. | |||
impl<'a,T, X: Deref<Target=[T]>> From<&'a X> for Stride<'a,T> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this would be slightly more general as
impl<'a, T, X: AsRef<[T]>> From<&'a X> for Stride<'a, T> {
}
And similarly with AsMut
for the mutability one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is AsRef
automatic for Deref
? Or will there be cases where AsRef
is not implemented but Deref
is?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not automatic, but it is more general, e.g. I believe the current From
implementation only works with X = &[T]
, meaning From::from(&[1, 2, 3])
doesn't work. However, the AsRef
version should work with X = [T]
so the latter does work.
(Actually, it will need to be X: ?Sized + AsRef<[T]>
.)
Tested a bit and it works for static arrays now. |
Thanks! |
As discussed on IRC.