Comments (2)
I'm open to this idea. I would love it if the function could take a slice instead of an array + length, but I don't know whether that will be possible.
Unfortunately,
panic!
in const contexts was only stabilized in Rust 1.57, which as far as I am aware would cause an issue since currently theconst_new
feature only requires Rust 1.51.
We could put the new function behind its own feature gate that requires Rust 1.57.
Also note that, as soon as I have time, I will be switching the main development branch to #284 which will be the basis for smallvec 2.0, which gives us a chance to increase the minimum Rust version and make other breaking changes.
from rust-smallvec.
I would love it if the function could take a slice instead of an array + length
I'm not sure how you could specify the logical capacity passing just a slice, though. Maybe I'm missing something.
Edit: Hm I guess you would do something like:
impl<T, const N: usize> SmallVec<[T; N]> {
// ...
pub const fn from_const_slice(items: &[T]) -> Self {
if items.len() >= N {
panic!("Expected length of slice to be less than or equal to array size");
}
SmallVec {
// ... something here
}
}
// ...
}
I guess I'm not sure how we can const
ly move a smaller size slice into a bigger array, since we want to move the contiguous slice into the SmallVec
.
from rust-smallvec.
Related Issues (20)
- support drain_filter ? HOT 12
- Store arbitrary types on `[u8; N]`? HOT 1
- CI failures due to dev_dependencies failing to build in Rust 1.36.0
- Add a `borsh` feature to get Borsh traits implemented
- Is this library support parallel iterator? HOT 3
- Make the v2 branch the default branch HOT 9
- Add a string type built on top of `SmallVec<u8>`? HOT 1
- Copy types
- Make a pre-release for v2 branch on crates.io HOT 1
- v1: `cargo doc` fails on nightly with `feature = "const_generics"` HOT 1
- test_size fails on 32-bit.
- implement `get_size::GetSize` for `SmallVec`, so we can know how much memory we're using? HOT 9
- README example no longer compiles HOT 1
- `SmallVec::insert` is UB on large arguments HOT 3
- Unable to deserialize the non-owned structures HOT 1
- Missing safety documentation for `Array` trait HOT 2
- Segfault on iter().collect() (2.0.0-alpha-5) HOT 3
- Implement `std::error::Error` for `CollectionAllocErr` HOT 1
- Wishlist: `TryFrom<SmallVec<A>> for [T; N]`
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from rust-smallvec.