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

Added feature const_new which enables SmallVec::new_const() #265

Merged
merged 4 commits into from Sep 28, 2021

Conversation

TimLuq
Copy link
Contributor

@TimLuq TimLuq commented Sep 24, 2021

As I wasn't alone in finding a use for having a const version of new (see #263) I decided to make a PR for it.

This adds a new feature flag const_new (nightly only) which exposes an alternative new function: pub const unsafe fn new_const() -> SmallVec<A>.

Nightly is needed for the binding A: Array, which could be worked around if the strict requirement is dropped from the struct declarations and moved only to the existing impls.

If the maintainers wish for another solution for this I'll be happy to make a few more commits.

@TimLuq
Copy link
Contributor Author

TimLuq commented Sep 25, 2021

I added from_const which behaves like from_buf for arrays ([_; N]). I also added a macro smallvec_inline that's just sugar for from_const.

My thought was that new_const and from_const should be visible in the docs. So the most recent commit also includes the changes necessary for displaying feature hints on docs.rs.

@mbrubeck
Copy link
Contributor

mbrubeck commented Sep 25, 2021

Could new_const be made safe by using const generics to implement it only for SmallVec<[T; N]>?

@TimLuq
Copy link
Contributor Author

TimLuq commented Sep 26, 2021

Could new_const be made safe by using const generics to implement it only for SmallVec<[T; N]>?

Yes, that is another option that should work. It will then be added to the same place as from_const which seems reasonable.

I'll be able to push a new commit in 8 hours or so. Is there anything else I should take a look at regarding this PR?

@TimLuq
Copy link
Contributor Author

TimLuq commented Sep 26, 2021

Limiting the const functions to SmallVec<[T; N]> also got rid of the need for the trait bound in addition to the unsafe keyword. This means it now builds in stable 1.51+ with the const_new feature active.

@mbrubeck
Copy link
Contributor

mbrubeck commented Sep 28, 2021

@bors-servo r+

@bors-servo
Copy link
Contributor

bors-servo commented Sep 28, 2021

📌 Commit 8320871 has been approved by mbrubeck

@bors-servo
Copy link
Contributor

bors-servo commented Sep 28, 2021

Testing commit 8320871 with merge 18b720f...

bors-servo added a commit that referenced this issue Sep 28, 2021
Added feature `const_new` which enables `SmallVec::new_const()`

As I wasn't alone in finding a use for having a `const` version of `new` (see #263) I decided to make a PR for it.

This adds a new feature flag `const_new` (nightly only) which exposes an alternative `new` function: `pub const unsafe fn new_const() -> SmallVec<A>`.

Nightly is needed for the binding `A: Array`, which could be worked around if the strict requirement is dropped from the `struct` declarations and moved only to the existing `impl`s.

If the maintainers wish for another solution for this I'll be happy to make a few more commits.
@mbrubeck mbrubeck merged commit 1e4b151 into servo:master Sep 28, 2021
1 check was pending
@mbrubeck
Copy link
Contributor

mbrubeck commented Sep 28, 2021

Thanks! This has been released in smallvec 1.7.0: https://crates.io/crates/smallvec/1.7.0

@bors-servo
Copy link
Contributor

bors-servo commented Sep 29, 2021

💥 Test timed out

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