diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index fa27d5b..5d22a00 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -13,7 +13,7 @@ jobs: build: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - name: Build run: cargo build --verbose - name: Run tests @@ -25,7 +25,7 @@ jobs: name: "Miri" runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - name: Install Miri run: | rustup toolchain install nightly --component miri @@ -37,35 +37,23 @@ jobs: fmt: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 - - uses: actions-rs/toolchain@v1 + - uses: actions/checkout@v4 + - uses: dtolnay/rust-toolchain@master with: toolchain: stable - profile: minimal components: rustfmt - override: true - - uses: actions-rs/cargo@v1 - with: - command: fmt - args: --all -- --check + - run: cargo fmt --all -- --check clippy: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 - - uses: actions-rs/toolchain@v1 + - uses: actions/checkout@v4 + - uses: dtolnay/rust-toolchain@master with: toolchain: stable - profile: minimal components: clippy - override: true - - uses: actions-rs/clippy-check@v1 - env: - PWD: ${{ env.GITHUB_WORKSPACE }} - with: - token: ${{ secrets.GITHUB_TOKEN }} - args: --workspace --tests --examples + - run: cargo clippy --workspace --tests --examples docs: @@ -73,15 +61,9 @@ jobs: env: RUSTDOCFLAGS: -Dwarnings steps: - - uses: actions/checkout@v2 - - uses: actions-rs/toolchain@v1 + - uses: actions/checkout@v4 + - uses: dtolnay/rust-toolchain@master with: toolchain: stable - profile: minimal - components: rust-docs - override: true - - uses: swatinem/rust-cache@v1 - - uses: actions-rs/cargo@v1 - with: - command: doc - args: --workspace --no-deps + - uses: swatinem/rust-cache@v2 + - run: cargo doc --workspace --no-deps diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 46f360c..0000000 --- a/.travis.yml +++ /dev/null @@ -1,21 +0,0 @@ -language: rust -sudo: false -matrix: - include: - - rust: stable - - rust: beta - - rust: nightly - - rust: nightly - env: FEATURES="--features eders" -script: - - cargo build $FEATURES - - cargo test $FEATURES - - cargo doc --no-deps -after_success: | - [ "$TRAVIS_RUST_VERSION" = nightly ] && - [ "$FEATURES" = "" ] && - [ "$TRAVIS_BRANCH" = master ] && - [ "$TRAVIS_PULL_REQUEST" = false ] && - bash deploy-docs.sh -notifications: - webhooks: http://huon.me:54857/travis diff --git a/Cargo.toml b/Cargo.toml index 6748036..31bd972 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -29,14 +29,14 @@ authors = ["Alex Crichton ", "Vadim Petrochenkov <>"] edition = "2018" -license = "MIT/Apache-2.0" +license = "MIT OR Apache-2.0" description = "A simple map based on a vector for small integer keys" repository = "https://github.com/contain-rs/vec-map" homepage = "https://github.com/contain-rs/vec-map" documentation = "https://contain-rs.github.io/vec-map/vec_map" keywords = ["data-structures", "collections", "vecmap", "vec_map", "contain-rs"] readme = "README.md" -exclude = ["/.travis.yml", "/deploy-docs.sh"] +exclude = ["/deploy-docs.sh"] [features] serde = ["dep:serde", "allocator-api2/serde"] diff --git a/README.md b/README.md index 8b0d4b9..41103dd 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,8 @@ -![Rust CI](https://github.com/contain-rs/vec-map/workflows/Rust/badge.svg?branch=master) [![crates.io](https://img.shields.io/crates/v/vec-map.svg)](https://crates.io/crates/vec-map) [![](https://docs.rs/vec-map/badge.svg)](https://docs.rs/vec-map) + +[![Rust](https://github.com/contain-rs/vec-map/actions/workflows/rust.yml/badge.svg)](https://github.com/contain-rs/vec-map/actions/workflows/rust.yml) +[![crates.io](https://img.shields.io/crates/v/vec_map.svg)](https://crates.io/crates/vec_map) +[![](https://docs.rs/vec_map/badge.svg)](https://docs.rs/vec_map) + **WARNING: THIS PROJECT IS IN MAINTENANCE MODE, DUE TO INSUFFICIENT MAINTAINER RESOURCES** @@ -14,4 +18,4 @@ We are currently only accepting changes which: A simple map based on a vector for small integer keys. -Documentation is available at https://contain-rs.github.io/vec-map/vec_map. +Documentation is available at . diff --git a/src/lib.rs b/src/lib.rs index e66fb1d..a4bc5ab 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -81,20 +81,20 @@ pub struct VecMap { /// A view into a single entry in a map, which may either be vacant or occupied. pub enum Entry<'a, V, A: Allocator = Global> { - /// A vacant Entry + /// A vacant `Entry` Vacant(VacantEntry<'a, V, A>), - /// An occupied Entry + /// An occupied `Entry` Occupied(OccupiedEntry<'a, V, A>), } -/// A vacant Entry. +/// A vacant `Entry`. pub struct VacantEntry<'a, V, A: Allocator = Global> { map: &'a mut VecMap, index: usize, } -/// An occupied Entry. +/// An occupied `Entry`. pub struct OccupiedEntry<'a, V, A: Allocator = Global> { map: &'a mut VecMap, index: usize, @@ -571,6 +571,9 @@ impl VecMap { /// Inserts a key-value pair into the map. If the key already had a value /// present in the map, that value is returned. Otherwise, `None` is returned. /// + /// *WARNING*: You should only use trusted values as keys in VecMap. Otherwise, a + /// denial-of-service vulnerability may occur that deplets memory with a large key value. + /// /// # Examples /// /// ``` @@ -707,7 +710,7 @@ impl<'a, V, A: Allocator> Entry<'a, V, A> { } impl<'a, V, A: Allocator> VacantEntry<'a, V, A> { - /// Sets the value of the entry with the VacantEntry's key, + /// Sets the value of the entry with the `VacantEntry`'s key, /// and returns a mutable reference to it. pub fn insert(self, value: V) -> &'a mut V { let index = self.index; @@ -735,7 +738,7 @@ impl<'a, V, A: Allocator> OccupiedEntry<'a, V, A> { &mut self.map[index] } - /// Sets the value of the entry with the OccupiedEntry's key, + /// Sets the value of the entry with the `OccupiedEntry`'s key, /// and returns the entry's old value. pub fn insert(&mut self, value: V) -> V { let index = self.index; @@ -946,6 +949,7 @@ macro_rules! double_ended_iterator { } /// An iterator over the key-value pairs of a map. +#[derive(Clone)] pub struct Iter<'a, V> { front: usize, back: usize, @@ -954,19 +958,6 @@ pub struct Iter<'a, V> { iter: slice::Iter<'a, Option>, } -// FIXME(#19839) Remove in favor of `#[derive(Clone)]` -impl<'a, V> Clone for Iter<'a, V> { - fn clone(&self) -> Iter<'a, V> { - Iter { - front: self.front, - back: self.back, - n: self.n, - yielded: self.yielded, - iter: self.iter.clone(), - } - } -} - iterator! { impl Iter -> (usize, &'a V), as_ref } impl<'a, V> ExactSizeIterator for Iter<'a, V> {} double_ended_iterator! { impl Iter -> (usize, &'a V), as_ref } @@ -986,33 +977,17 @@ impl<'a, V> ExactSizeIterator for IterMut<'a, V> {} double_ended_iterator! { impl IterMut -> (usize, &'a mut V), as_mut } /// An iterator over the keys of a map. +#[derive(Clone)] pub struct Keys<'a, V> { iter: Iter<'a, V>, } -// FIXME(#19839) Remove in favor of `#[derive(Clone)]` -impl<'a, V> Clone for Keys<'a, V> { - fn clone(&self) -> Keys<'a, V> { - Keys { - iter: self.iter.clone(), - } - } -} - /// An iterator over the values of a map. +#[derive(Clone)] pub struct Values<'a, V> { iter: Iter<'a, V>, } -// FIXME(#19839) Remove in favor of `#[derive(Clone)]` -impl<'a, V> Clone for Values<'a, V> { - fn clone(&self) -> Values<'a, V> { - Values { - iter: self.iter.clone(), - } - } -} - /// An iterator over the values of a map. pub struct ValuesMut<'a, V> { iter_mut: IterMut<'a, V>,