Skip to content

bring back zip methods - #60

Closed
baloo wants to merge 2 commits into
RustCrypto:masterfrom
baloo:baloo/functional
Closed

bring back zip methods#60
baloo wants to merge 2 commits into
RustCrypto:masterfrom
baloo:baloo/functional

Conversation

@baloo

@baloobaloo commented Mar 4, 2024

Copy link
Copy Markdown
Member

@baloo

baloo commented Mar 4, 2024

Copy link
Copy Markdown
MemberAuthor

The only purpose of using a trait here is to limit API breakage with generic-array but it's otherwise not required.

Now I comment on it, I kind of feel I should have gone with a straight impl Array block. Opinion?

@tarcieri

tarcieri commented Mar 4, 2024

Copy link
Copy Markdown
Member

Yes, these should just be inherent methods. GenericArray was weird for defining traits for everything, being the only implementor, and then writing blanket impls, which only makes it annoying to pull those traits into scope.

No unsafe code should be required for any of these. You should be able to leverage the FromIterator/IntoIterator impls, either on core arrays or on Array, e.g. Array::map can be written Array(self.0.map(f)).

It'd also be good to update the migration guide.

@baloo
balooforce-pushed the baloo/functional branch from 746c92c to 9e49060CompareMarch 4, 2024 16:50
Comment threadsrc/functional.rs Outdated
Comment threadsrc/functional.rs Outdated
@baloo
balooforce-pushed the baloo/functional branch from 9e49060 to d077d6cCompareMarch 4, 2024 17:05
@baloobaloo changed the title bring back FunctionalSequencebring back map/zip methodsMar 4, 2024
@tarcieri

Copy link
Copy Markdown
Member

Perhaps we can just add Array::map and for zip and join suggest using IntoIterator instead in the migration guide: https://github.com/RustCrypto/hybrid-array/blob/b362ec7/src/lib.rs#L66

@tarcieri

tarcieri commented Mar 4, 2024

Copy link
Copy Markdown
Member

map looks good, but zip seems weird to me, as in there's [T; N]::map defined in core, but no corresponding zip method in core.

I'm not sure this really deserves its own module either, especially if it's just map.

@baloo

baloo commented Mar 4, 2024

Copy link
Copy Markdown
MemberAuthor

well, we could do a into_iter().zip(other_array) but this doesn't strictly enforces the size which would be missing.
https://doc.rust-lang.org/std/iter/trait.Iterator.html#method.zip.

I don't know how to write a migration guide without just copy pasting this implementation every time.

@baloo
balooforce-pushed the baloo/functional branch from d077d6c to 6189dc8CompareMarch 4, 2024 18:34
@baloobaloo changed the title bring back map/zip methodsbring back zip methodsMar 4, 2024
@baloo
balooforce-pushed the baloo/functional branch from 6189dc8 to 3edacdbCompareMarch 4, 2024 18:36
@baloo
balooforce-pushed the baloo/functional branch from 3edacdb to cc092a6CompareMarch 4, 2024 18:36
@tarcieri

Copy link
Copy Markdown
Member

Where is it actually being used?

If we do add it, I think it should be deprecated.

@baloo

baloo commented Mar 4, 2024

Copy link
Copy Markdown
MemberAuthor

@tarcieri

tarcieri commented Mar 4, 2024

Copy link
Copy Markdown
Member

Yikes, that's gross!

let full_tag = self.nonce.zip(h, |a, b| a ^ b).zip(c, |a, b| a ^ b);Tag::<M>::clone_from_slice(&full_tag[..M::to_usize()])

It looks like it could be replaced by something like:

self.nonce.into_iter().zip(h, |a, b| a ^ b).take(M::to_usize()).collect()

@tarcieri

Copy link
Copy Markdown
Member

I guess I should also mention: one of the goals of hybrid-array is to be shaped a lot closer to core arrays, to aid an eventual transition to core arrays.

I would prefer not to continue to provide generic-array esoterisms, and if we do they should only be to aid a transition, and deprecated.

@baloo

baloo commented Mar 4, 2024

Copy link
Copy Markdown
MemberAuthor

the only benefit I've seen from having a zip implementation was the enforcement of the sizes.

But in the case of eax, this is enforced externally (message and data being the same size / type).
Yeah. I guess we can go with the into_iter()

@baloobaloo closed this Mar 4, 2024
@baloo
baloo deleted the baloo/functional branch March 4, 2024 19:16
@tarcieri

Copy link
Copy Markdown
Member

FWIW bringing back map still seems good to me

@baloo

baloo commented Mar 4, 2024

Copy link
Copy Markdown
MemberAuthor

well, it was in your branch?
I didn't a use for it quite yet.

@tarcieri

Copy link
Copy Markdown
Member

I don't have a branch

@baloo

baloo commented Mar 4, 2024

Copy link
Copy Markdown
MemberAuthor

@baloobaloo mentioned this pull request Mar 4, 2024
tarcieri added a commit that referenced this pull request Mar 5, 2024
Alternative to #60
Co-authored-by: Tony Arcieri <bascule@gmail.com>
Sign up for freeto 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.

2 participants

@baloo@tarcieri