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

Implement [value; N] syntax support for array_vec! #118

Merged
merged 4 commits into from
Oct 12, 2020
Merged

Implement [value; N] syntax support for array_vec! #118

merged 4 commits into from
Oct 12, 2020

Conversation

slightlyoutofphase
Copy link
Contributor

Closes #117. I also improved one of the other variants of the macro a little bit while I was at it.

Also implement the `($array_type:ty)` form by just calling `default()` immediately, which makes more sense.
@Lokathor Lokathor requested a review from Nemo157 September 14, 2020 22:07
Copy link
Owner

@Lokathor Lokathor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like it, but I'm gonna ping Nemo as well for a double check.

@Nemo157
Copy link
Collaborator

Nemo157 commented Sep 15, 2020

Implementation looks fine, but it seems weird to support this syntax for array_vec! and not tiny_vec!.

@slightlyoutofphase
Copy link
Contributor Author

Implementation looks fine, but it seems weird to support this syntax for array_vec! and not tiny_vec!.

I can add that as well, if you'd like.

Also make the same improvement to the `($array_type:ty)` macro variant that I did for `array_vec!`.
@slightlyoutofphase
Copy link
Contributor Author

Ok, added it for tiny_vec! as well, and added a test.

@Nemo157
Copy link
Collaborator

Nemo157 commented Sep 16, 2020

// Given that this works:
let vec: TinyVec<[f32; 4]> = tiny_vec![1.1, 1.1, 1.1];

// Should this work:
let vec: TinyVec<[f32; 4]> = tiny_vec![1.1; 3];

@slightlyoutofphase
Copy link
Contributor Author

For both ArrayVec and TinyVec?

@Lokathor
Copy link
Owner

hmm, that's a very good question.

@Nemo157
Copy link
Collaborator

Nemo157 commented Sep 17, 2020

The first form works for both, so if it's possible (/easy enough) it seems good to have the second form for both.

@Lokathor
Copy link
Owner

Lokathor commented Oct 9, 2020

@slightlyoutofphase Hi, looks like we all forgot about this a bit.

did you want to add that one final macro variant to this PR? Or I can just merge it now.

@Lokathor Lokathor merged commit 0529972 into Lokathor:main Oct 12, 2020
@Lokathor
Copy link
Owner

oh, forgot to say at the time. near as i can tell it looks like the requested style was already implemented by the time it was asked.

@Nemo157
Copy link
Collaborator

Nemo157 commented Oct 12, 2020

8 |     let vec: TinyVec<[f32; 4]> = tiny_vec![1.1; 3];
  |              -----------------   ^^^^^^^^^^^^^^^^^ expected an array with a fixed size of 4 elements, found one with 3 elements
  |              |
  |              expected due to this

(I also just realised that the inverse could be supported by tiny_vec! (and not array_vec!): let vec: TinyVec<[f32; 4]> = tiny_vec![1.1; 5];, going directly to an allocation).

@slightlyoutofphase
Copy link
Contributor Author

slightlyoutofphase commented Nov 13, 2020

Hey guys, sorry I didn't get back to you. Basically, after playing around with a bunch of things, I found that it isn't quite possible to make the code example given by @Nemo157, that is, this:

// Given that this works:
let vec: TinyVec<[f32; 4]> = tiny_vec![1.1, 1.1, 1.1];

// Should this work:
let vec: TinyVec<[f32; 4]> = tiny_vec![1.1; 3];

work at the moment. The compiler isn't quite smart enough currently to see through the ambiguity such that both versions can exist and work in their appropriate contexts at the same time.

If it gets to the point where I think this can be done though, I'll for sure come back and add it for you if you want.

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.

The array_vec! macro does not support the array-like [T; N] syntax you'd generally expect it to
3 participants