Code Monkey home page Code Monkey logo

staticvec's People

Contributors

5225225 avatar batisteo avatar c410-f3r avatar delamonpansie avatar gavento avatar jswrenn avatar lucretiel avatar nilsirl avatar paulocsanz avatar rsschermer avatar slightlyoutofphase avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

staticvec's Issues

Integrate StaticString with serde (and maybe diesel - partially)

Hey, this wasn't really in the scope of the first PR, and I'm not that motivated to refactor to use const generics, although it's probably an easy change. I may actually do it if I want to procrastinate from other stuff, but I can't promise it.

I've already implemented integration for ArrayString (the basis of the current StaticString) with serde and partially with diesel. I don't remember how well the diesel one works, but it's actually tested so it may be interesting to re-use it, or just ignore for now (diesel kinda sucks to integrate with, most stuff needed are private and they are unwilling to stabilize it in a public API, so some things can't be done with StaticString, but some may be).

You can see the original implementation here: https://github.com/paulocsanz/arraystring/blob/master/src/integration.rs it there is any interest

Add specialized `T: Copy` implementation of `Clone`

Once trait specialization (rust-lang/rust#31844) is stabilized, create a T: Copy specialization of Clone, which simply copies the slice without relying on the optimizer to notice that it can be done that way. This will allow us to replace a number of "manual copies" with calls to self.clone().

Example of manual copy:

staticvec/src/lib.rs

Lines 508 to 519 in da97905

pub fn sorted(&self) -> Self
where T: Copy + Ord {
unsafe {
let mut res = Self::new();
res.length = self.length;
self
.as_ptr()
.copy_to_nonoverlapping(res.as_mut_ptr(), self.length);
res.sort();
res
}
}

add `const_intrinsic_copy` to rust features

   Compiling staticvec v0.11.6
error: `ptr::mut_ptr::<impl *mut T>::copy_from_nonoverlapping` is not yet stable as a const fn
  --> /home/codespace/.cargo/registry/src/github.com-1ecc6299db9ec823/staticvec-0.11.6/src/heap/heap_trait_impls.rs:38:7
   |
38 | /       self
39 | |         .data
40 | |         .as_mut_ptr()
41 | |         .copy_from_nonoverlapping(source.data.as_ptr(), source.data.length);
   | |___________________________________________________________________________^
   |
   = help: add `#![feature(const_intrinsic_copy)]` to the crate attributes to enable

There's not actually any practical reason for the `length` field of a StaticVec to be of type `usize`

It's just kinda unavoidable due to nothing else being accepted as an array index in Rust (despite the fact that I'm quite sure it's not even possible to instantiate a static array with a length anywhere close to where you'd need usize indices, because you'd overflow the stack way before then.)

u32 would make significantly more sense IMO (at least on x64) and probably improve performance in places due to the layout optimizations I believe it would allow for. It's unclear what an ergonomic way to do it is, though.

Any suggestions / opinions would be very welcome!

staticsort depends on libstd

I can't use this crate with no_std because the staticsort crate which is a dependency of staticvec depends on std.

How unstable is this library?

I see this library is using many unstable features. I'm wondering how much these features are actually required considering that the similar crate smallvec is providing a superset of staticvec but without using unstable features.

`transmute_copy` possibly innefficient

// The code this generates is *way* more efficient than `copy_to_nonoverlapping`,

Are there any concerns about the specialized Clone impl being inefficient for large StaticVecs with small lengths? For instance:

let buffer: StaticVec<u8, 4096> = (0..10).collect();

// This will copy 4096 bytes instead of 10 
let buffer2 = buffer.clone();

Support for CI

Build is currently broken on master and there should be a CI script to at least inform users which commit is green.

Compilation fails on latest nightly (e77366b57 2023-05-16)

Hi. Thanks for your crate.
I notice that staticvec is not building with latest nightly:

❯ rustc -V
rustc 1.71.0-nightly (e77366b57 2023-05-16)
❯ cargo build
    Updating crates.io index
   Compiling staticvec v0.11.9 (/home/esteban/dev/staticvec)
warning: the feature `const_ptr_read` has been stable since 1.71.0-nightly and no longer requires an attribute to enable
  --> src/lib.rs:45:3
   |
45 |   const_ptr_read,
   |   ^^^^^^^^^^^^^^
   |
   = note: `#[warn(stable_features)]` on by default

error: ~const can only be applied to `#[const_trait]` traits
    --> src/lib.rs:1420:26
     |
1420 |   where T: Copy + ~const PartialOrd {
     |                          ^^^^^^^^^^

error: ~const can only be applied to `#[const_trait]` traits
    --> src/lib.rs:1455:26
     |
1455 |   where T: Copy + ~const PartialOrd {
     |                          ^^^^^^^^^^

error: const `impl` for trait `Clone` which is not marked with `#[const_trait]`
  --> src/heap/heap_trait_impls.rs:25:37
   |
25 | impl<T: Copy, const N: usize> const Clone for StaticHeap<T, N> {
   |                                     ^^^^^
   |
   = note: marking a trait with `#[const_trait]` ensures all default method bodies are `const`
   = note: adding a non-const method body in the future would be a breaking change

error: const `impl` for trait `Default` which is not marked with `#[const_trait]`
  --> src/heap/heap_trait_impls.rs:47:36
   |
47 | impl<T: Ord, const N: usize> const Default for StaticHeap<T, N> {
   |                                    ^^^^^^^
   |
   = note: marking a trait with `#[const_trait]` ensures all default method bodies are `const`
   = note: adding a non-const method body in the future would be a breaking change

error: const `impl` for trait `IntoIterator` which is not marked with `#[const_trait]`
   --> src/heap/heap_trait_impls.rs:199:31
    |
199 | impl<T, const N: usize> const IntoIterator for StaticHeap<T, N> {
    |                               ^^^^^^^^^^^^
    |
    = note: marking a trait with `#[const_trait]` ensures all default method bodies are `const`
    = note: adding a non-const method body in the future would be a breaking change

error: const `impl` for trait `IntoIterator` which is not marked with `#[const_trait]`
   --> src/heap/heap_trait_impls.rs:225:35
    |
225 | impl<'a, T, const N: usize> const IntoIterator for &'a StaticHeap<T, N> {
    |                                   ^^^^^^^^^^^^
    |
    = note: marking a trait with `#[const_trait]` ensures all default method bodies are `const`
    = note: adding a non-const method body in the future would be a breaking change

error: const `impl` for trait `IntoIterator` which is not marked with `#[const_trait]`
   --> src/heap/heap_trait_impls.rs:235:35
    |
235 | impl<'a, T, const N: usize> const IntoIterator for &'a mut StaticHeap<T, N> {
    |                                   ^^^^^^^^^^^^
    |
    = note: marking a trait with `#[const_trait]` ensures all default method bodies are `const`
    = note: adding a non-const method body in the future would be a breaking change

error: const `impl` for trait `From` which is not marked with `#[const_trait]`
  --> src/string/string_errors.rs:75:12
   |
75 | impl const From<DecodeUtf16Error> for StringError {
   |            ^^^^^^^^^^^^^^^^^^^^^^
   |
   = note: marking a trait with `#[const_trait]` ensures all default method bodies are `const`
   = note: adding a non-const method body in the future would be a breaking change

error: const `impl` for trait `From` which is not marked with `#[const_trait]`
  --> src/string/string_errors.rs:82:12
   |
82 | impl const From<Utf8Error> for StringError {
   |            ^^^^^^^^^^^^^^^
   |
   = note: marking a trait with `#[const_trait]` ensures all default method bodies are `const`
   = note: adding a non-const method body in the future would be a breaking change

error: const `impl` for trait `From` which is not marked with `#[const_trait]`
  --> src/string/string_errors.rs:89:28
   |
89 | impl<const N: usize> const From<CapacityError<N>> for StringError {
   |                            ^^^^^^^^^^^^^^^^^^^^^^
   |
   = note: marking a trait with `#[const_trait]` ensures all default method bodies are `const`
   = note: adding a non-const method body in the future would be a breaking change

error: const `impl` for trait `AsMut` which is not marked with `#[const_trait]`
  --> src/string/string_trait_impls.rs:39:28
   |
39 | impl<const N: usize> const AsMut<str> for StaticString<N> {
   |                            ^^^^^^^^^^
   |
   = note: marking a trait with `#[const_trait]` ensures all default method bodies are `const`
   = note: adding a non-const method body in the future would be a breaking change

error: const `impl` for trait `AsRef` which is not marked with `#[const_trait]`
  --> src/string/string_trait_impls.rs:46:28
   |
46 | impl<const N: usize> const AsRef<str> for StaticString<N> {
   |                            ^^^^^^^^^^
   |
   = note: marking a trait with `#[const_trait]` ensures all default method bodies are `const`
   = note: adding a non-const method body in the future would be a breaking change

error: const `impl` for trait `AsRef` which is not marked with `#[const_trait]`
  --> src/string/string_trait_impls.rs:53:28
   |
53 | impl<const N: usize> const AsRef<[u8]> for StaticString<N> {
   |                            ^^^^^^^^^^^
   |
   = note: marking a trait with `#[const_trait]` ensures all default method bodies are `const`
   = note: adding a non-const method body in the future would be a breaking change

error: const `impl` for trait `Borrow` which is not marked with `#[const_trait]`
  --> src/string/string_trait_impls.rs:60:28
   |
60 | impl<const N: usize> const Borrow<str> for StaticString<N> {
   |                            ^^^^^^^^^^^
   |
   = note: marking a trait with `#[const_trait]` ensures all default method bodies are `const`
   = note: adding a non-const method body in the future would be a breaking change

error: const `impl` for trait `BorrowMut` which is not marked with `#[const_trait]`
  --> src/string/string_trait_impls.rs:67:28
   |
67 | impl<const N: usize> const BorrowMut<str> for StaticString<N> {
   |                            ^^^^^^^^^^^^^^
   |
   = note: marking a trait with `#[const_trait]` ensures all default method bodies are `const`
   = note: adding a non-const method body in the future would be a breaking change

error: const `impl` for trait `Clone` which is not marked with `#[const_trait]`
  --> src/string/string_trait_impls.rs:74:28
   |
74 | impl<const N: usize> const Clone for StaticString<N> {
   |                            ^^^^^
   |
   = note: marking a trait with `#[const_trait]` ensures all default method bodies are `const`
   = note: adding a non-const method body in the future would be a breaking change

error: const `impl` for trait `Default` which is not marked with `#[const_trait]`
   --> src/string/string_trait_impls.rs:106:28
    |
106 | impl<const N: usize> const Default for StaticString<N> {
    |                            ^^^^^^^
    |
    = note: marking a trait with `#[const_trait]` ensures all default method bodies are `const`
    = note: adding a non-const method body in the future would be a breaking change

error: const `impl` for trait `Deref` which is not marked with `#[const_trait]`
   --> src/string/string_trait_impls.rs:113:28
    |
113 | impl<const N: usize> const Deref for StaticString<N> {
    |                            ^^^^^
    |
    = note: marking a trait with `#[const_trait]` ensures all default method bodies are `const`
    = note: adding a non-const method body in the future would be a breaking change

error: const `impl` for trait `DerefMut` which is not marked with `#[const_trait]`
   --> src/string/string_trait_impls.rs:122:28
    |
122 | impl<const N: usize> const DerefMut for StaticString<N> {
    |                            ^^^^^^^^
    |
    = note: marking a trait with `#[const_trait]` ensures all default method bodies are `const`
    = note: adding a non-const method body in the future would be a breaking change

error: const `impl` for trait `Index` which is not marked with `#[const_trait]`
   --> src/string/string_trait_impls.rs:262:28
    |
262 | impl<const N: usize> const Index<RangeFull> for StaticString<N> {
    |                            ^^^^^^^^^^^^^^^^
    |
    = note: marking a trait with `#[const_trait]` ensures all default method bodies are `const`
    = note: adding a non-const method body in the future would be a breaking change

error: const `impl` for trait `IndexMut` which is not marked with `#[const_trait]`
   --> src/string/string_trait_impls.rs:271:28
    |
271 | impl<const N: usize> const IndexMut<RangeFull> for StaticString<N> {
    |                            ^^^^^^^^^^^^^^^^^^^
    |
    = note: marking a trait with `#[const_trait]` ensures all default method bodies are `const`
    = note: adding a non-const method body in the future would be a breaking change

error: const `impl` for trait `AsMut` which is not marked with `#[const_trait]`
  --> src/trait_impls.rs:47:31
   |
47 | impl<T, const N: usize> const AsMut<[T]> for StaticVec<T, N> {
   |                               ^^^^^^^^^^
   |
   = note: marking a trait with `#[const_trait]` ensures all default method bodies are `const`
   = note: adding a non-const method body in the future would be a breaking change

error: const `impl` for trait `AsRef` which is not marked with `#[const_trait]`
  --> src/trait_impls.rs:54:31
   |
54 | impl<T, const N: usize> const AsRef<[T]> for StaticVec<T, N> {
   |                               ^^^^^^^^^^
   |
   = note: marking a trait with `#[const_trait]` ensures all default method bodies are `const`
   = note: adding a non-const method body in the future would be a breaking change

error: const `impl` for trait `Borrow` which is not marked with `#[const_trait]`
  --> src/trait_impls.rs:61:31
   |
61 | impl<T, const N: usize> const Borrow<[T]> for StaticVec<T, N> {
   |                               ^^^^^^^^^^^
   |
   = note: marking a trait with `#[const_trait]` ensures all default method bodies are `const`
   = note: adding a non-const method body in the future would be a breaking change

error: const `impl` for trait `BorrowMut` which is not marked with `#[const_trait]`
  --> src/trait_impls.rs:68:31
   |
68 | impl<T, const N: usize> const BorrowMut<[T]> for StaticVec<T, N> {
   |                               ^^^^^^^^^^^^^^
   |
   = note: marking a trait with `#[const_trait]` ensures all default method bodies are `const`
   = note: adding a non-const method body in the future would be a breaking change

error: const `impl` for trait `Clone` which is not marked with `#[const_trait]`
   --> src/trait_impls.rs:112:37
    |
112 | impl<T: Copy, const N: usize> const Clone for StaticVec<T, N> {
    |                                     ^^^^^
    |
    = note: marking a trait with `#[const_trait]` ensures all default method bodies are `const`
    = note: adding a non-const method body in the future would be a breaking change

error: const `impl` for trait `Default` which is not marked with `#[const_trait]`
   --> src/trait_impls.rs:153:31
    |
153 | impl<T, const N: usize> const Default for StaticVec<T, N> {
    |                               ^^^^^^^
    |
    = note: marking a trait with `#[const_trait]` ensures all default method bodies are `const`
    = note: adding a non-const method body in the future would be a breaking change

error: const `impl` for trait `Deref` which is not marked with `#[const_trait]`
   --> src/trait_impls.rs:161:31
    |
161 | impl<T, const N: usize> const Deref for StaticVec<T, N> {
    |                               ^^^^^
    |
    = note: marking a trait with `#[const_trait]` ensures all default method bodies are `const`
    = note: adding a non-const method body in the future would be a breaking change

error: const `impl` for trait `DerefMut` which is not marked with `#[const_trait]`
   --> src/trait_impls.rs:169:31
    |
169 | impl<T, const N: usize> const DerefMut for StaticVec<T, N> {
    |                               ^^^^^^^^
    |
    = note: marking a trait with `#[const_trait]` ensures all default method bodies are `const`
    = note: adding a non-const method body in the future would be a breaking change

error: const `impl` for trait `From` which is not marked with `#[const_trait]`
   --> src/trait_impls.rs:362:37
    |
362 | impl<T: Copy, const N: usize> const From<&[T]> for StaticVec<T, N> {
    |                                     ^^^^^^^^^^
    |
    = note: marking a trait with `#[const_trait]` ensures all default method bodies are `const`
    = note: adding a non-const method body in the future would be a breaking change

error: const `impl` for trait `From` which is not marked with `#[const_trait]`
   --> src/trait_impls.rs:371:37
    |
371 | impl<T: Copy, const N: usize> const From<&mut [T]> for StaticVec<T, N> {
    |                                     ^^^^^^^^^^^^^^
    |
    = note: marking a trait with `#[const_trait]` ensures all default method bodies are `const`
    = note: adding a non-const method body in the future would be a breaking change

error: const `impl` for trait `From` which is not marked with `#[const_trait]`
   --> src/trait_impls.rs:389:31
    |
389 | impl<T, const N: usize> const From<[T; N]> for StaticVec<T, N> {
    |                               ^^^^^^^^^^^^
    |
    = note: marking a trait with `#[const_trait]` ensures all default method bodies are `const`
    = note: adding a non-const method body in the future would be a breaking change

error: const `impl` for trait `From` which is not marked with `#[const_trait]`
   --> src/trait_impls.rs:396:55
    |
396 | impl<T: Copy, const N1: usize, const N2: usize> const From<&[T; N1]> for StaticVec<T, N2> {
    |                                                       ^^^^^^^^^^^^^^
    |
    = note: marking a trait with `#[const_trait]` ensures all default method bodies are `const`
    = note: adding a non-const method body in the future would be a breaking change

error: const `impl` for trait `From` which is not marked with `#[const_trait]`
   --> src/trait_impls.rs:405:37
    |
405 | impl<T: Copy, const N: usize> const From<&[T; N]> for StaticVec<T, N> {
    |                                     ^^^^^^^^^^^^^
    |
    = note: marking a trait with `#[const_trait]` ensures all default method bodies are `const`
    = note: adding a non-const method body in the future would be a breaking change

error: const `impl` for trait `From` which is not marked with `#[const_trait]`
   --> src/trait_impls.rs:414:55
    |
414 | impl<T: Copy, const N1: usize, const N2: usize> const From<&mut [T; N1]> for StaticVec<T, N2> {
    |                                                       ^^^^^^^^^^^^^^^^^^
    |
    = note: marking a trait with `#[const_trait]` ensures all default method bodies are `const`
    = note: adding a non-const method body in the future would be a breaking change

error: const `impl` for trait `From` which is not marked with `#[const_trait]`
   --> src/trait_impls.rs:423:37
    |
423 | impl<T: Copy, const N: usize> const From<&mut [T; N]> for StaticVec<T, N> {
    |                                     ^^^^^^^^^^^^^^^^^
    |
    = note: marking a trait with `#[const_trait]` ensures all default method bodies are `const`
    = note: adding a non-const method body in the future would be a breaking change

error: const `impl` for trait `Index` which is not marked with `#[const_trait]`
   --> src/trait_impls.rs:495:31
    |
495 | impl<T, const N: usize> const Index<usize> for StaticVec<T, N> {
    |                               ^^^^^^^^^^^^
    |
    = note: marking a trait with `#[const_trait]` ensures all default method bodies are `const`
    = note: adding a non-const method body in the future would be a breaking change

error: const `impl` for trait `IndexMut` which is not marked with `#[const_trait]`
   --> src/trait_impls.rs:518:31
    |
518 | impl<T, const N: usize> const IndexMut<usize> for StaticVec<T, N> {
    |                               ^^^^^^^^^^^^^^^
    |
    = note: marking a trait with `#[const_trait]` ensures all default method bodies are `const`
    = note: adding a non-const method body in the future would be a breaking change

error: const `impl` for trait `Index` which is not marked with `#[const_trait]`
   --> src/trait_impls.rs:540:31
    |
540 | impl<T, const N: usize> const Index<Range<usize>> for StaticVec<T, N> {
    |                               ^^^^^^^^^^^^^^^^^^^
    |
    = note: marking a trait with `#[const_trait]` ensures all default method bodies are `const`
    = note: adding a non-const method body in the future would be a breaking change

error: const `impl` for trait `IndexMut` which is not marked with `#[const_trait]`
   --> src/trait_impls.rs:554:31
    |
554 | impl<T, const N: usize> const IndexMut<Range<usize>> for StaticVec<T, N> {
    |                               ^^^^^^^^^^^^^^^^^^^^^^
    |
    = note: marking a trait with `#[const_trait]` ensures all default method bodies are `const`
    = note: adding a non-const method body in the future would be a breaking change

error: const `impl` for trait `Index` which is not marked with `#[const_trait]`
   --> src/trait_impls.rs:572:31
    |
572 | impl<T, const N: usize> const Index<RangeFrom<usize>> for StaticVec<T, N> {
    |                               ^^^^^^^^^^^^^^^^^^^^^^^
    |
    = note: marking a trait with `#[const_trait]` ensures all default method bodies are `const`
    = note: adding a non-const method body in the future would be a breaking change

error: const `impl` for trait `IndexMut` which is not marked with `#[const_trait]`
   --> src/trait_impls.rs:589:31
    |
589 | impl<T, const N: usize> const IndexMut<RangeFrom<usize>> for StaticVec<T, N> {
    |                               ^^^^^^^^^^^^^^^^^^^^^^^^^^
    |
    = note: marking a trait with `#[const_trait]` ensures all default method bodies are `const`
    = note: adding a non-const method body in the future would be a breaking change

error: const `impl` for trait `Index` which is not marked with `#[const_trait]`
   --> src/trait_impls.rs:605:31
    |
605 | impl<T, const N: usize> const Index<RangeFull> for StaticVec<T, N> {
    |                               ^^^^^^^^^^^^^^^^
    |
    = note: marking a trait with `#[const_trait]` ensures all default method bodies are `const`
    = note: adding a non-const method body in the future would be a breaking change

error: const `impl` for trait `IndexMut` which is not marked with `#[const_trait]`
   --> src/trait_impls.rs:615:31
    |
615 | impl<T, const N: usize> const IndexMut<RangeFull> for StaticVec<T, N> {
    |                               ^^^^^^^^^^^^^^^^^^^
    |
    = note: marking a trait with `#[const_trait]` ensures all default method bodies are `const`
    = note: adding a non-const method body in the future would be a breaking change

error: const `impl` for trait `Index` which is not marked with `#[const_trait]`
   --> src/trait_impls.rs:624:31
    |
624 | impl<T, const N: usize> const Index<RangeInclusive<usize>> for StaticVec<T, N> {
    |                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |
    = note: marking a trait with `#[const_trait]` ensures all default method bodies are `const`
    = note: adding a non-const method body in the future would be a breaking change

error: const `impl` for trait `IndexMut` which is not marked with `#[const_trait]`
   --> src/trait_impls.rs:638:31
    |
638 | impl<T, const N: usize> const IndexMut<RangeInclusive<usize>> for StaticVec<T, N> {
    |                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |
    = note: marking a trait with `#[const_trait]` ensures all default method bodies are `const`
    = note: adding a non-const method body in the future would be a breaking change

error: const `impl` for trait `Index` which is not marked with `#[const_trait]`
   --> src/trait_impls.rs:651:31
    |
651 | impl<T, const N: usize> const Index<RangeTo<usize>> for StaticVec<T, N> {
    |                               ^^^^^^^^^^^^^^^^^^^^^
    |
    = note: marking a trait with `#[const_trait]` ensures all default method bodies are `const`
    = note: adding a non-const method body in the future would be a breaking change

error: const `impl` for trait `IndexMut` which is not marked with `#[const_trait]`
   --> src/trait_impls.rs:663:31
    |
663 | impl<T, const N: usize> const IndexMut<RangeTo<usize>> for StaticVec<T, N> {
    |                               ^^^^^^^^^^^^^^^^^^^^^^^^
    |
    = note: marking a trait with `#[const_trait]` ensures all default method bodies are `const`
    = note: adding a non-const method body in the future would be a breaking change

error: const `impl` for trait `Index` which is not marked with `#[const_trait]`
   --> src/trait_impls.rs:674:31
    |
674 | impl<T, const N: usize> const Index<RangeToInclusive<usize>> for StaticVec<T, N> {
    |                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |
    = note: marking a trait with `#[const_trait]` ensures all default method bodies are `const`
    = note: adding a non-const method body in the future would be a breaking change

error: const `impl` for trait `IndexMut` which is not marked with `#[const_trait]`
   --> src/trait_impls.rs:686:31
    |
686 | impl<T, const N: usize> const IndexMut<RangeToInclusive<usize>> for StaticVec<T, N> {
    |                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |
    = note: marking a trait with `#[const_trait]` ensures all default method bodies are `const`
    = note: adding a non-const method body in the future would be a breaking change

error: const `impl` for trait `IntoIterator` which is not marked with `#[const_trait]`
   --> src/trait_impls.rs:708:39
    |
708 | impl<'a, T: 'a, const N: usize> const IntoIterator for &'a StaticVec<T, N> {
    |                                       ^^^^^^^^^^^^
    |
    = note: marking a trait with `#[const_trait]` ensures all default method bodies are `const`
    = note: adding a non-const method body in the future would be a breaking change

error: const `impl` for trait `IntoIterator` which is not marked with `#[const_trait]`
   --> src/trait_impls.rs:719:39
    |
719 | impl<'a, T: 'a, const N: usize> const IntoIterator for &'a mut StaticVec<T, N> {
    |                                       ^^^^^^^^^^^^
    |
    = note: marking a trait with `#[const_trait]` ensures all default method bodies are `const`
    = note: adding a non-const method body in the future would be a breaking change

error: const `impl` for trait `IntoIterator` which is not marked with `#[const_trait]`
   --> src/trait_impls.rs:730:31
    |
730 | impl<T, const N: usize> const IntoIterator for StaticVec<T, N> {
    |                               ^^^^^^^^^^^^
    |
    = note: marking a trait with `#[const_trait]` ensures all default method bodies are `const`
    = note: adding a non-const method body in the future would be a breaking change

error: ~const can only be applied to `#[const_trait]` traits
   --> src/utils.rs:177:57
    |
177 | pub(crate) const fn quicksort_internal<T: Copy + ~const PartialOrd>(
    |                                                         ^^^^^^^^^^

warning: `staticvec` (lib) generated 1 warning
error: could not compile `staticvec` (lib) due to 54 previous errors; 1 warning emitted

Add a `StaticVecDeque` type

Hi,

I see you also provide derived types such as StaticHeap and StaticString. What would you think about adding a StaticVecDeque type mimicking the standard VecDeque? It would be super useful although it cannot be directly implemented from StaticVec since some elements on the front of the vec might be uninitialized...

Doesn't compile on latest nightly

error[E0015]: calls in constant functions are limited to constant functions, tuple structs and tuple variants
   --> /home/user/.cargo/registry/src/github.com-xxxx/staticvec-0.10.8/src/lib.rs:771:5
    |
771 |     self.mut_ptr_at_unchecked(length).write(value);
    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Figure out how to use `push_unchecked` in more places

There's an issue in which using push_unchecked in loops, even with a fixed number of iterations, causes inferior assembly to be generated. For example:

staticvec/src/lib.rs

Lines 116 to 133 in 4b2534f

#[inline]
pub fn filled_with<F>(mut initializer: F) -> Self
where F: FnMut() -> T {
let mut res = Self::new();
//You might think it would make more sense to use `push_unchecked` here.
//Originally, I did also! However, as of today (November 19, 2019), doing so
//both in this function and several others throughout the crate inhibits the ability
//of `rustc` to fully unroll and autovectorize various constant-bounds loops. If this changes
//in the future, feel free to open a PR switching out the manual code for `get_unchecked`, if
//you happen to notice it before I do.
for i in 0..N {
unsafe {
res.data.get_unchecked_mut(i).write(initializer());
res.length += 1;
}
}
res
}

The workaround is to manually push by writing directly to self.data and incrementing self.length. However, we'd prefer to minimize the amount of unsafe code we have to write, and we'd rather use "safer unsafes" like push_unchecked that provide a friendlier contract than self.data.get_unchecked_mut().write.

Implement `core::fmt::Write` for `StaticVec`

StaticVec currently implements std::io::Write when std is enabled. If it supports core::fmt::Write, consumers of the type can use the vector as a target for formatting in a no_std environment.

Inconsistency in panicking string methods and truncating ones

The API is inconsistent about panicking.

push, push_str and insert panic, but insert_str, from_chars, from_str, from_utf8, from_utf16 default to truncating.

It would make sense making the others panic and add a truncating alternative, or drop the panicking ones all together (what was done in the original implementation). It may be a little less ergonomic to panic by default, but it also allows for a library that you know will never panicking, making it much more useful in embed systems (except for Indexes traits).

It's a though trade-off tho, since this is a breaking change, it may have to wait for 8.0 (but this can be documented).

Also, the remove method doesn't panic, but the docs says it does. (it panics in debug only, but it really shouldn't, not if it returns Result, actually, checking the code, a bunch of debug_assertions can be dropped, since they are basically checking that functions like is_char_boundary or is_inside_boundary work), debug_assertions are great to discover UB before it happens.

Doesn't compile on latest nightly

This PR broke the current functionality: rust-lang/rust#70107
Starting with the June 3rd nightly, staticvec fails to build.
IIUC, this is not a compiler bug, but rather a feature.
I think that until const bounds are implemented, there is no way to implement concat and all the other "combination" helpers.

error: constant expression depends on a generic parameter
    --> /Users/yotam/.cargo/registry/src/github.com-1ecc6299db9ec823/staticvec-0.9.3/src/lib.rs:1467:70
     |
1467 |   pub fn concat<const N2: usize>(&self, other: &StaticVec<T, N2>) -> StaticVec<T, { N + N2 }>
     |                                                                      ^^^^^^^^^^^^^^^^^^^^^^^^
     |
     = note: this may fail depending on what value the parameter takes

Miri flag passing changed

cargo miri test changed to be more compatible with cargo test, but this means we had to find a different way to pass flags to the interpreter, so there now is a MIRIFLAGS environment variable for that. The old way still works for now, but is deprecated.

This affects the following line:

cargo miri test --features="std" -- -Zmiri-disable-isolation

That should now be MIRIFLAGS="-Zmiri-disable-isolation" cargo miri test --features="std". cargo miri setup is also not needed any more.

sort/sorted, reverse/reversed both accept `&mut self`

StaticVec::reversed(&mut self)->StaticVec<..> probably should not accept &mut self but only &self to indicate that the original instance does not change. The same for sorted_.... It may be easy to confuse reversed with e.g. "a reverse that also returns Self".

Implement Copy for StaticString

Currently, StaticString doesn't implement Copy because its implementation relies upon StaticVec, which also doesn't implement Copy. I suggest the creation of another "copyable" structure like StaticVecCopy (I don't know :P) with a macro or a trait to avoid internal code duplication.

`MaybeUninit::read` has been renamed into `assume_init_read`

Hi,

yesterday the MaybeUninit::read function has been renamed into assume_init_read via this commit. It has been briefly discussed here before that. Of course this means that staticvec does not compile with the lastest nightly build.

    --> src/lib.rs:1693:29
     |
1693 |       unsafe { Ok(self.data.read()) }
     |                             ^^^^ method not found in `MaybeUninit<[T; N]>`

Write::write_all is incorrect

fn write_all(&mut self, buf: &[u8]) -> io::Result<()> {

write_all needs to guarantee that all of the input bytes were written to the underlying writer. If the StaticVec doesn't have enough capacity, it only writes the beginning of the slice, but still reports success.

Other collections on stack

Are you planning on adding other collections? Like HashMap/HashSet, VecDeque, BinaryHeap? I found that "heapless" crate providing BinaryHeap on stack is slow for some reason. I tried copying BinaryHeap from std and changing Vec to StaticVec(and removing a lot of stuff that I didn't care), worked like a charm!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.