Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .clippy.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
allow-unwrap-in-consts = true
allow-unwrap-in-tests = true
13 changes: 3 additions & 10 deletions .github/workflows/blobby.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ name: blobby

on:
pull_request:
paths:
- "blobby/**"
- "Cargo.*"
paths:
- "blobby/**"
- "Cargo.*"
push:
branches: master

Expand Down Expand Up @@ -38,11 +38,4 @@ jobs:
- uses: dtolnay/rust-toolchain@master
with:
toolchain: ${{ matrix.rust }}
# Isolate this crate from workspace which is otherwise MSRV 1.56 due to 2021 edition crates
- run: rm ../Cargo.toml
- run: cargo test

minimal-versions:
uses: RustCrypto/actions/.github/workflows/minimal-versions.yml@master
with:
working-directory: ${{ github.workflow }}
6 changes: 3 additions & 3 deletions .github/workflows/block-buffer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ name: block-buffer

on:
pull_request:
paths:
- "block-buffer/**"
- "Cargo.*"
paths:
- "block-buffer/**"
- "Cargo.*"
push:
branches: master

Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/block-padding.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ name: block-padding

on:
pull_request:
paths:
- "block-padding/**"
- "Cargo.*"
paths:
- "block-padding/**"
- "Cargo.*"
push:
branches: master

Expand Down Expand Up @@ -47,7 +47,7 @@ jobs:
minimal-versions:
uses: RustCrypto/actions/.github/workflows/minimal-versions.yml@master
with:
working-directory: ${{ github.workflow }}
working-directory: ${{ github.workflow }}

test:
runs-on: ubuntu-latest
Expand Down
10 changes: 1 addition & 9 deletions .github/workflows/cpufeatures.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
minimal-versions:
uses: RustCrypto/actions/.github/workflows/minimal-versions.yml@master
with:
working-directory: ${{ github.workflow }}
working-directory: ${{ github.workflow }}

# Linux tests
linux:
Expand Down Expand Up @@ -56,8 +56,6 @@ jobs:
with:
toolchain: ${{ matrix.rust }}
targets: ${{ matrix.target }}
# Isolate this crate from workspace which is otherwise MSRV 1.56 due to 2021 edition crates
- run: rm ../Cargo.toml
- run: ${{ matrix.deps }}
- run: cargo test --target ${{ matrix.target }}

Expand All @@ -76,8 +74,6 @@ jobs:
with:
toolchain: ${{ matrix.toolchain }}
targets: x86_64-apple-darwin
# Isolate this crate from workspace which is otherwise MSRV 1.56 due to 2021 edition crates
- run: rm ../Cargo.toml
- run: cargo test

# Windows tests
Expand All @@ -98,8 +94,6 @@ jobs:
with:
toolchain: ${{ matrix.toolchain }}
targets: ${{ matrix.target }}
# Isolate this crate from workspace which is otherwise MSRV 1.56 due to 2021 edition crates
- run: rm ../Cargo.toml
- run: cargo test --target ${{ matrix.target }}

# Cross-compiled tests
Expand All @@ -121,8 +115,6 @@ jobs:
toolchain: ${{ matrix.rust }}
targets: ${{ matrix.target }}
- uses: RustCrypto/actions/cross-install@master
# Isolate this crate from workspace which is otherwise MSRV 1.56 due to 2021 edition crates
- run: rm ../Cargo.toml
- run: cross test --target ${{ matrix.target }}

# Build-only tests
Expand Down
12 changes: 4 additions & 8 deletions .github/workflows/hex-literal.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ name: hex-literal

on:
pull_request:
paths:
- "hex-literal/**"
- "Cargo.*"
paths:
- "hex-literal/**"
- "Cargo.*"
push:
branches: master

Expand Down Expand Up @@ -42,14 +42,12 @@ jobs:
with:
toolchain: ${{ matrix.rust }}
targets: ${{ matrix.target }}
# Isolate this crate from workspace which is otherwise MSRV 1.56 due to 2021 edition crates
- run: rm ../Cargo.toml
- run: cargo build --target ${{ matrix.target }}

minimal-versions:
uses: RustCrypto/actions/.github/workflows/minimal-versions.yml@master
with:
working-directory: ${{ github.workflow }}
working-directory: ${{ github.workflow }}

test:
runs-on: ubuntu-latest
Expand All @@ -64,6 +62,4 @@ jobs:
- uses: dtolnay/rust-toolchain@master
with:
toolchain: ${{ matrix.rust }}
# Isolate this crate from workspace which is otherwise MSRV 1.56 due to 2021 edition crates
- run: rm ../Cargo.toml
- run: cargo test
8 changes: 4 additions & 4 deletions .github/workflows/inout.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ name: inout

on:
pull_request:
paths:
- "inout/**"
- "Cargo.*"
paths:
- "inout/**"
- "Cargo.*"
push:
branches: master

Expand Down Expand Up @@ -48,7 +48,7 @@ jobs:
minimal-versions:
uses: RustCrypto/actions/.github/workflows/minimal-versions.yml@master
with:
working-directory: ${{ github.workflow }}
working-directory: ${{ github.workflow }}

test:
runs-on: ubuntu-latest
Expand Down
15 changes: 3 additions & 12 deletions .github/workflows/opaque-debug.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ name: opaque-debug

on:
pull_request:
paths:
- "opaque-debug/**"
- "Cargo.*"
paths:
- "opaque-debug/**"
- "Cargo.*"
push:
branches: master

Expand Down Expand Up @@ -42,15 +42,8 @@ jobs:
with:
toolchain: ${{ matrix.rust }}
targets: ${{ matrix.target }}
# Isolate this crate from workspace which is otherwise MSRV 1.56 due to 2021 edition crates
- run: rm ../Cargo.toml
- run: cargo build --target ${{ matrix.target }}

minimal-versions:
uses: RustCrypto/actions/.github/workflows/minimal-versions.yml@master
with:
working-directory: ${{ github.workflow }}

test:
runs-on: ubuntu-latest
strategy:
Expand All @@ -64,6 +57,4 @@ jobs:
- uses: dtolnay/rust-toolchain@master
with:
toolchain: ${{ matrix.rust }}
# Isolate this crate from workspace which is otherwise MSRV 1.56 due to 2021 edition crates
- run: rm ../Cargo.toml
- run: cargo test
39 changes: 39 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,42 @@ opt-level = 2

[patch.crates-io]
cmov = { path = "cmov" }

[workspace.lints.clippy]
borrow_as_ptr = "warn"
cast_lossless = "warn"
cast_possible_truncation = "warn"
cast_possible_wrap = "warn"
cast_precision_loss = "warn"
cast_sign_loss = "warn"
checked_conversions = "warn"
doc_markdown = "warn"
from_iter_instead_of_collect = "warn"
manual_assert = "warn"
map_unwrap_or = "warn"
missing_errors_doc = "warn"
missing_panics_doc = "warn"
mod_module_files = "warn"
must_use_candidate = "warn"
implicit_saturating_sub = "warn"
ptr_as_ptr = "warn"
redundant_closure_for_method_calls = "warn"
ref_as_ptr = "warn"
return_self_not_must_use = "warn"
semicolon_if_nothing_returned = "warn"
trivially_copy_pass_by_ref = "warn"
std_instead_of_alloc = "warn"
std_instead_of_core = "warn"
undocumented_unsafe_blocks = "warn"
unnecessary_safety_comment = "warn"
unwrap_in_result = "warn"
unwrap_used = "warn"

[workspace.lints.rust]
missing_copy_implementations = "warn"
missing_debug_implementations = "warn"
missing_docs = "warn"
trivial_casts = "warn"
trivial_numeric_casts = "warn"
unused_lifetimes = "warn"
unused_qualifications = "warn"
3 changes: 3 additions & 0 deletions blobby/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,6 @@ description = "Iterator over simple binary blob storage"

[features]
alloc = []

[lints]
workspace = true
2 changes: 1 addition & 1 deletion blobby/src/bin/decode.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//! Encoding utility
use std::error::Error;
use core::error::Error;

#[cfg(not(feature = "alloc"))]
fn main() -> Result<(), Box<dyn Error>> {
Expand Down
2 changes: 1 addition & 1 deletion blobby/src/bin/encode.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//! Encoding utility
use std::error::Error;
use core::error::Error;

#[cfg(not(feature = "alloc"))]
fn main() -> Result<(), Box<dyn Error>> {
Expand Down
15 changes: 14 additions & 1 deletion blobby/src/decode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ macro_rules! try_read_vlq {
}

/// Blobby file header
#[derive(Clone, Copy, Debug)]
pub struct Header {
/// Number of blobs stored in the file
pub items_len: usize,
Expand All @@ -59,7 +60,10 @@ pub struct Header {
}

impl Header {
/// Parse blobby header
/// Parse blobby header.
///
/// # Errors
/// If data could not be parsed successfully.
pub const fn parse(data: &mut &[u8]) -> Result<Self, Error> {
match (read_vlq(data), read_vlq(data)) {
(Ok(items_len), Ok(dedup_len)) => Ok(Header {
Expand All @@ -72,6 +76,9 @@ impl Header {
}

/// Parse blobby data into an array.
///
/// # Errors
/// If data could not be parsed successfully.
pub const fn parse_into_array<const ITEMS_LEN: usize, const DEDUP_LEN: usize>(
mut data: &[u8],
) -> Result<[&[u8]; ITEMS_LEN], Error> {
Expand Down Expand Up @@ -127,7 +134,11 @@ pub const fn parse_into_array<const ITEMS_LEN: usize, const DEDUP_LEN: usize>(
}

/// Parse blobby data into a vector of slices.
///
/// # Errors
/// If data failed to parse successfully
#[cfg(feature = "alloc")]
#[allow(clippy::missing_panics_doc)]
pub fn parse_into_vec(mut data: &[u8]) -> Result<alloc::vec::Vec<&[u8]>, Error> {
use alloc::{vec, vec::Vec};

Expand Down Expand Up @@ -175,6 +186,7 @@ pub fn parse_into_vec(mut data: &[u8]) -> Result<alloc::vec::Vec<&[u8]>, Error>
Ok(res)
}

/// Parse data into a slice.
#[macro_export]
macro_rules! parse_into_slice {
($data:expr) => {{
Expand All @@ -195,6 +207,7 @@ macro_rules! parse_into_slice {
}};
}

/// Parse data into structs.
#[macro_export]
macro_rules! parse_into_structs {
(
Expand Down
7 changes: 5 additions & 2 deletions blobby/src/encode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use super::{NEXT_MASK, VAL_MASK};
/// Write a git-flavoured VLQ value into `buf`.
///
/// Returns the slice within `buf` that holds the value.
#[allow(clippy::cast_possible_truncation)]
fn encode_vlq(mut val: usize, buf: &mut [u8; 4]) -> &[u8] {
macro_rules! step {
($n:expr) => {
Expand Down Expand Up @@ -40,6 +41,7 @@ fn encode_vlq(mut val: usize, buf: &mut [u8; 4]) -> &[u8] {
/// - (J << 1) & 0x01: indicates this blob is index entry J
/// - (L << 1) & 0x00: indicates an explicit blob of len L
/// - (in the latter case) explicit blob contents (L bytes)
#[allow(clippy::missing_panics_doc, clippy::unwrap_used)]
pub fn encode_blobs<T>(blobs: &[T]) -> (alloc::vec::Vec<u8>, usize)
where
T: AsRef<[u8]>,
Expand All @@ -49,7 +51,7 @@ where
let mut dedup_map = BTreeMap::new();
blobs
.iter()
.map(|v| v.as_ref())
.map(AsRef::as_ref)
.filter(|blob| !blob.is_empty())
.for_each(|blob| {
let v = dedup_map.entry(blob.as_ref()).or_insert(0);
Expand Down Expand Up @@ -89,7 +91,7 @@ where
out_buf.extend_from_slice(e);
}

for blob in blobs.iter().map(|v| v.as_ref()) {
for blob in blobs.iter().map(AsRef::as_ref) {
if let Some(dup_pos) = rev_idx.get(blob) {
let n = (dup_pos << 1) + 1usize;
out_buf.extend_from_slice(encode_vlq(n, &mut buf));
Expand All @@ -104,6 +106,7 @@ where
}

#[cfg(test)]
#[allow(clippy::cast_possible_truncation, clippy::unwrap_used)]
mod tests {
use crate::{Error, NEXT_MASK, VAL_MASK, decode::read_vlq};

Expand Down
2 changes: 2 additions & 0 deletions blobby/tests/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//! `blobby` tests
#![cfg(feature = "alloc")]

const ITEMS_LEN: usize = 10;
Expand All @@ -15,6 +16,7 @@ const TEST_BLOBS: &[&[u8]; ITEMS_LEN] = &[
&[13; 5_000],
];

/// Performs a round-trip test.
#[test]
fn blobby_rondtrip_test() -> Result<(), blobby::Error> {
let (blobby_data, dedup_len) = blobby::encode_blobs(TEST_BLOBS);
Expand Down
3 changes: 3 additions & 0 deletions block-buffer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,6 @@ zeroize = { version = "1.4", optional = true, default-features = false }

[dev-dependencies]
hex-literal = "1"

[lints]
workspace = true
Loading