Skip to content

Commit

Permalink
Merge pull request #107 from artichoke/symboltable-shrink-to
Browse files Browse the repository at this point in the history
Implement `shrink_to` on all `SymbolTable`s, declare Rust 1.56.0 MSRV, upgrade to 2021 edition
  • Loading branch information
lopopolo authored Nov 18, 2021
2 parents a077572 + 7508e06 commit 7c9a236
Show file tree
Hide file tree
Showing 6 changed files with 96 additions and 4 deletions.
32 changes: 32 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,38 @@ jobs:
- name: Test with no default features
run: cargo test --no-default-features --target ${{ matrix.target }}

build-msrv:
name: Build (1.56.0)
runs-on: ubuntu-latest
env:
CARGO_INCREMENTAL: 0
RUSTFLAGS: -D warnings
RUST_BACKTRACE: 1
steps:
- name: Checkout repository
uses: actions/checkout@v2

- name: Install Rust toolchain
uses: actions-rs/toolchain@v1
with:
toolchain: "1.56.0"
profile: minimal

- name: Compile
run: cargo build --verbose

- name: Compile tests
run: cargo test --no-run

- name: Test
run: cargo test

- name: Test with all features
run: cargo test --all-features

- name: Test with no default features
run: cargo test --no-default-features

rust:
name: Lint and format Rust
runs-on: ubuntu-latest
Expand Down
5 changes: 3 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
[package]
name = "intaglio"
version = "1.3.0" # remember to set `html_root_url` in `src/lib.rs`.
version = "1.4.0" # remember to set `html_root_url` in `src/lib.rs`.
authors = ["Ryan Lopopolo <[email protected]>"]
license = "MIT"
edition = "2018"
edition = "2021"
rust-version = "1.56.0"
readme = "README.md"
repository = "https://github.com/artichoke/intaglio"
documentation = "https://docs.rs/intaglio"
Expand Down
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ Add this to your `Cargo.toml`:

```toml
[dependencies]
intaglio = "1.3"
intaglio = "1.4"
```

Then intern UTF-8 strings like:
Expand Down Expand Up @@ -79,6 +79,11 @@ All features are enabled by default.
- **bytes** - Enables an additional symbol table implementation for interning
bytestrings (`Vec<u8>` and `&'static [u8]`).

### Minimum Supported Rust Version

This crate requires at least Rust 1.56.0. This version can be bumped in minor
releases.

## License

`intaglio` is licensed under the [MIT License](LICENSE) (c) Ryan Lopopolo.
Expand Down
27 changes: 27 additions & 0 deletions src/bytes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -845,6 +845,33 @@ where
self.map.shrink_to_fit();
self.vec.shrink_to_fit();
}

/// Shrinks the capacity of the symbol table with a lower bound.
///
/// The capacity will remain at least as large as both the length and the
/// supplied value.
///
/// If the current capacity is less than the lower limit, this is a no-op.
///
/// # Examples
///
/// ```
/// # use intaglio::bytes::SymbolTable;
/// # fn example() -> Result<(), Box<dyn std::error::Error>> {
/// let mut table = SymbolTable::with_capacity(10);
/// table.intern(b"abc".to_vec())?;
/// table.intern(b"xyz".to_vec())?;
/// table.intern(b"123".to_vec())?;
/// table.shrink_to(5);
/// assert!(table.capacity() >= 5);
/// # Ok(())
/// # }
/// # example().unwrap();
/// ```
pub fn shrink_to(&mut self, min_capacity: usize) {
self.map.shrink_to(min_capacity);
self.vec.shrink_to(min_capacity);
}
}

#[cfg(test)]
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
//! - **bytes** - Enables an additional symbol table implementation for
//! interning bytestrings (`Vec<u8>` and `&'static [u8]`).
#![doc(html_root_url = "https://docs.rs/intaglio/1.3.0")]
#![doc(html_root_url = "https://docs.rs/intaglio/1.4.0")]

// Ensure code blocks in README.md compile
#[cfg(doctest)]
Expand Down
27 changes: 27 additions & 0 deletions src/str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -784,6 +784,33 @@ where
self.map.shrink_to_fit();
self.vec.shrink_to_fit();
}

/// Shrinks the capacity of the symbol table with a lower bound.
///
/// The capacity will remain at least as large as both the length and the
/// supplied value.
///
/// If the current capacity is less than the lower limit, this is a no-op.
///
/// # Examples
///
/// ```
/// # use intaglio::SymbolTable;
/// # fn example() -> Result<(), Box<dyn std::error::Error>> {
/// let mut table = SymbolTable::with_capacity(10);
/// table.intern("abc")?;
/// table.intern("xyz")?;
/// table.intern("123")?;
/// table.shrink_to(5);
/// assert!(table.capacity() >= 5);
/// # Ok(())
/// # }
/// # example().unwrap();
/// ```
pub fn shrink_to(&mut self, min_capacity: usize) {
self.map.shrink_to(min_capacity);
self.vec.shrink_to(min_capacity);
}
}

#[cfg(test)]
Expand Down

0 comments on commit 7c9a236

Please sign in to comment.