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 GenericSequence, Lengthen, Shorten, Split and Concat traits. #50

Merged
merged 6 commits into from
Feb 18, 2018

Conversation

novacrazy
Copy link
Collaborator

Here are some more useful features that allow for easier passing of GenericArray via generics, as well as some simple resize methods implemented as inverse traits. I've had to use these a few times already.

These really should have been in that last pull request, but I wasn't far enough along in a dependent project to really test it.

@novacrazy
Copy link
Collaborator Author

The whole "inverse trait" idea is useful because of arrays like GenericArray<T, U0>, where it can't be shortened anymore but could be lengthened. However, the lengthened array should be able to be shortened again to get the original GenericArray<T, U0>.

In type Longer: Shorten<T, Shorter=Self> (and Shorten trait equivalent), the Shorter=Self clause allows Rust to correctly deduce that type of self.lengthen(_).shorten().0 is equal to Self, which is awesome.

@novacrazy
Copy link
Collaborator Author

In fact, would you like the idea of me adding head, tail, init and last methods for segmenting arrays on the type level? I could probably implement a generic split method and use it for the others.

@fizyk20
Copy link
Owner

fizyk20 commented Sep 23, 2017

Wow, very nice ideas! Yes, the methods you mention sound awesome, it would be great if you added them :)

@novacrazy novacrazy changed the title Add GenericSequence, Lengthen and Shorten traits. Add GenericSequence, Lengthen, Shorten, Split and Concat traits. Nov 21, 2017
@novacrazy
Copy link
Collaborator Author

novacrazy commented Nov 21, 2017

A few changes which cover your other pull request.

I've redesigned the Lengthen and Shorten traits. They are still inverse traits, but instead of lengthen and shorten methods, we now have append, prepend, pop_back and pop_front. These are more familiar and follow more traditional terminology.

I've also added the Split and Concat traits. These are NOT inverse traits for now. I'm not sure they even could be, given how arbitrary they are.

Also, I've simplified the logic I use for these. Since it's literally just moving/copying data, I've followed your example and simplified things to raw pointer operations. They can't panic, so it's fine.

Overall, I'd say it's pretty complete. If you're happy with this then I can't think of anything else to hold off for.

Edit: One last naming convention change.

@fizyk20 fizyk20 merged commit 04f16db into fizyk20:master Feb 18, 2018
@fizyk20
Copy link
Owner

fizyk20 commented Feb 18, 2018

Thanks! And sorry for the delay in merging :)

@novacrazy
Copy link
Collaborator Author

So you're going to hate me for this, but I promise I'm not trying to make things harder on you.

I'm working on some new improvements to this stuff that should be ready in a week or two.

I just wanted to warn you before doing that semver trick thing in case you are willing to wait.

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

2 participants