Skip to content

Commit

Permalink
README updates.
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Huszagh committed Aug 21, 2019
1 parent 0b22f46 commit 128954b
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,34 @@ rust-stackvector

"StackVec": vector-like facade for stack-allocated arrays.

# Comparison to ArrayVec

[ArrayVec](https://github.com/bluss/arrayvec) is a relatively mature stack vector implementation, using a backing array like stackvector. The main differences between ArrayVec and StackVec are in the compatibility with Vec's API, as well as the ease-of-creation.

**Initialization**

For initialization, ArrayVec offers only construction of an empty container (`new`), while stackvector offers initialization of:

1. An empty container (`new`).
2. From a vector (`from_vec`).
3. From a stack-allocated array (`from_buf`).

This comment has been minimized.

Copy link
@matklad

This comment has been minimized.

Copy link
@Alexhuszagh

Alexhuszagh Aug 22, 2019

Owner

@matklad Thanks, I'll update this again. To be fair, it doesn't have 3, which initializes from a stack-allocated buffer without any copying.

This comment has been minimized.

Copy link
@matklad

matklad Aug 22, 2019

Hm, this looks like zero copy to me:

impl<A: Array> From<A> for ArrayVec<A> {
    fn from(array: A) -> Self {
        ArrayVec { xs: MaybeUninit::from(array), len: Index::from(A::capacity()) }
    }
}

This comment has been minimized.

Copy link
@Alexhuszagh

Alexhuszagh Aug 26, 2019

Owner

@matklad Thanks for correcting my mistakes, fixed as of the latest commit.


**Compatibility with Vec's API**

ArrayVec includes numerous modifications from Vec's API, effectively requiring a wrapper to use it analogously to Vec. In certain situations, the extra functionality is desirable (for example, ArrayVec has `push`, which panics if the container exceeds the array's bounds, `try_push`, and `push_unchecked`, while stackvector only has `push`). In other cases, ArrayVec is missing numerous methods that simplify working with Vec. For example, ArrayVec is missing:

1. Deduplication (`dedup`, `dedup_by`, `dedup_by_key`).
2. Insert many elements (`insert_many`) (Non-standard).

Likewise, stackvector is missing certain convenience methods that are not present in Vec:

1. Stack-allocated array is full (`is_full`).
2. Dispose without dropping (`dispose`).

**Version Support**

Both ArrayVec and stackvector have support for Rustc versions as old as 1.20.0.

# License

StackVector is derived from Servo's [smallvec](https://github.com/servo/rust-smallve), and like smallvec, it is dual licensed under either the MIT or Apache 2.0 license.
Expand Down

0 comments on commit 128954b

Please sign in to comment.