Skip to content
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

Merged
merged 1 commit into from
Aug 10, 2015
Merged

Add From implementations. #3

merged 1 commit into from
Aug 10, 2015

Conversation

meh
Copy link
Contributor

@meh meh commented Aug 1, 2015

As discussed on IRC.

@autohuonw
Copy link
Collaborator

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> {
Copy link
Owner

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.

Copy link
Contributor Author

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?

Copy link
Owner

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]>.)

@meh
Copy link
Contributor Author

meh commented Aug 4, 2015

Tested a bit and it works for static arrays now.

huonw added a commit that referenced this pull request Aug 10, 2015
Add From implementations.
@huonw huonw merged commit 4f07c0d into huonw:master Aug 10, 2015
@huonw
Copy link
Owner

huonw commented Aug 10, 2015

Thanks!

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.

None yet

3 participants