Skip to content

Commit

Permalink
Merge branch 'master' into perf-copy-to-bytes-bytes
Browse files Browse the repository at this point in the history
  • Loading branch information
tisonkun authored Apr 9, 2024
2 parents d6bcaa2 + e4af486 commit cd1401c
Show file tree
Hide file tree
Showing 18 changed files with 324 additions and 275 deletions.
54 changes: 31 additions & 23 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ on:
push:
branches:
- master
schedule:
- cron: '0 2 * * 0'

env:
RUSTFLAGS: -Dwarnings
Expand All @@ -23,19 +25,19 @@ jobs:
name: rustfmt
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Install Rust
run: rustup update stable && rustup default stable
run: rustup update stable
- name: Check formatting
run: cargo fmt --all -- --check
run: cargo fmt --all --check

# TODO
# # Apply clippy lints
# clippy:
# name: clippy
# runs-on: ubuntu-latest
# steps:
# - uses: actions/checkout@v3
# - uses: actions/checkout@v4
# - name: Apply clippy lints
# run: cargo clippy --all-features

Expand All @@ -48,11 +50,11 @@ jobs:
name: minrust
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Install Rust
run: rustup update 1.39.0 && rustup default 1.39.0
- uses: actions/checkout@v4
- name: Install cargo-hack
uses: taiki-e/install-action@cargo-hack
- name: Check
run: . ci/test-stable.sh check
run: cargo hack check --feature-powerset --optional-deps --rust-version

# Stable
stable:
Expand All @@ -65,23 +67,27 @@ jobs:
- windows-latest
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Install Rust
# --no-self-update is necessary because the windows environment cannot self-update rustup.exe.
run: rustup update stable --no-self-update && rustup default stable
run: rustup update stable --no-self-update
- name: Install cargo-hack
uses: taiki-e/install-action@cargo-hack
- name: Test
run: . ci/test-stable.sh test
run: ci/test-stable.sh test

# Nightly
nightly:
name: nightly
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Install Rust
run: rustup update $nightly && rustup default $nightly
- name: Install cargo-hack
uses: taiki-e/install-action@cargo-hack
- name: Test
run: . ci/test-stable.sh test
run: ci/test-stable.sh test

# Run tests on some extra platforms
cross:
Expand All @@ -96,13 +102,14 @@ jobs:
- wasm32-unknown-unknown
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Install Rust
run: rustup update stable && rustup default stable
run: rustup update stable
- name: Install cross
uses: taiki-e/install-action@cross
if: matrix.target != 'wasm32-unknown-unknown'
- name: cross build --target ${{ matrix.target }}
run: |
cargo install cross
cross build --target ${{ matrix.target }}
run: cross build --target ${{ matrix.target }}
if: matrix.target != 'wasm32-unknown-unknown'
# WASM support
- name: cargo build --target ${{ matrix.target }}
Expand All @@ -116,18 +123,19 @@ jobs:
name: tsan
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Install Rust
run: rustup update $nightly && rustup default $nightly
- name: Install rust-src
run: rustup component add rust-src
- name: ASAN / TSAN
run: . ci/tsan.sh
run: ci/tsan.sh

miri:
name: miri
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Miri
run: ci/miri.sh

Expand All @@ -136,7 +144,7 @@ jobs:
name: loom
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Install Rust
run: rustup update $nightly && rustup default $nightly
- name: Loom tests
Expand All @@ -155,7 +163,7 @@ jobs:
- loom
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Install Rust
run: rustup update $nightly && rustup default $nightly
- name: Build documentation
Expand Down
37 changes: 37 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,40 @@
# 1.6.0 (March 22, 2024)

### Added

- Add `Bytes::is_unique` (#643)

### Documented

- Fix changelog typo (#628)
- Fix some spelling mistakes (#633)
- Typo fix (#637)
- Fix broken links (#639)
- Add security policy (#649)

### Internal changes

- Move comment to correct constant (#629)
- Various cleanup (#635)
- Simplify `UninitSlice::as_uninit_slice_mut()` logic (#644)
- Use `self.` instead of `Self::` (#642)
- `BytesMut`: Assert alignment of `Shared` (#652)
- Remove unnecessary namespace qualifier (#660)
- Remove an unnecessary else branch (#662)
- Remove unreachable else branch (#661)
- make parameter mut in `From<Vec>` (#667)
- Restore commented tests (#665)
- Use `sub` instead of `offset` (#668)
- Calculate original capacity only if necessary (#666)
- `set_vec_pos` does not need a second parameter (#672)
- `get_vec_pos`: use `&self` instead of `&mut self` (#670)
- Refactor `split_at`/`split_to` (#663)
- Use `Iterator` from the prelude (#673)
- `copy_to_bytes`: Add panic section to docs (#676)
- Remove redundant reserve call (#674)
- Use `ManuallyDrop` instead of `mem::forget` (#675)


# 1.5.0 (September 7, 2023)

### Added
Expand Down
7 changes: 4 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ name = "bytes"
# When releasing to crates.io:
# - Update CHANGELOG.md.
# - Create "v1.x.y" git tag.
version = "1.5.0"
version = "1.6.0"
edition = "2018"
rust-version = "1.39"
license = "MIT"
authors = [
"Carl Lerche <[email protected]>",
Expand All @@ -15,7 +17,6 @@ repository = "https:/tokio-rs/bytes"
readme = "README.md"
keywords = ["buffers", "zero-copy", "io"]
categories = ["network-programming", "data-structures"]
edition = "2018"

[features]
default = ["std"]
Expand All @@ -28,7 +29,7 @@ serde = { version = "1.0.60", optional = true, default-features = false, feature
serde_test = "1.0"

[target.'cfg(loom)'.dev-dependencies]
loom = "0.5"
loom = "0.7"

[package.metadata.docs.rs]
rustdoc-args = ["--cfg", "docsrs"]
9 changes: 9 additions & 0 deletions SECURITY.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Security Policy

Bytes is part of the Tokio project and uses the same security policy as [Tokio][tokio-security].

## Report a security issue

The process for reporting an issue is the same as for [Tokio][tokio-security]. This includes private reporting via [email protected].

[tokio-security]: https:/tokio-rs/tokio/security/policy
6 changes: 0 additions & 6 deletions ci/test-stable.sh
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,13 @@ set -ex

cmd="${1:-test}"

# Install cargo-hack for feature flag test
host=$(rustc -Vv | grep host | sed 's/host: //')
curl -LsSf https:/taiki-e/cargo-hack/releases/latest/download/cargo-hack-$host.tar.gz | tar xzf - -C ~/.cargo/bin

# Run with each feature
# * --each-feature includes both default/no-default features
# * --optional-deps is needed for serde feature
cargo hack "${cmd}" --each-feature --optional-deps
# Run with all features
cargo "${cmd}" --all-features

cargo doc --no-deps --all-features

if [[ "${RUST_VERSION}" == "nightly"* ]]; then
# Check benchmarks
cargo check --benches
Expand Down
Empty file modified ci/tsan.sh
100644 → 100755
Empty file.
16 changes: 10 additions & 6 deletions src/buf/buf_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -991,7 +991,7 @@ pub trait Buf {
///
/// This function panics if there is not enough remaining data in `self`.
fn get_f32(&mut self) -> f32 {
f32::from_bits(Self::get_u32(self))
f32::from_bits(self.get_u32())
}

/// Gets an IEEE754 single-precision (4 bytes) floating point number from
Expand All @@ -1012,7 +1012,7 @@ pub trait Buf {
///
/// This function panics if there is not enough remaining data in `self`.
fn get_f32_le(&mut self) -> f32 {
f32::from_bits(Self::get_u32_le(self))
f32::from_bits(self.get_u32_le())
}

/// Gets an IEEE754 single-precision (4 bytes) floating point number from
Expand All @@ -1036,7 +1036,7 @@ pub trait Buf {
///
/// This function panics if there is not enough remaining data in `self`.
fn get_f32_ne(&mut self) -> f32 {
f32::from_bits(Self::get_u32_ne(self))
f32::from_bits(self.get_u32_ne())
}

/// Gets an IEEE754 double-precision (8 bytes) floating point number from
Expand All @@ -1057,7 +1057,7 @@ pub trait Buf {
///
/// This function panics if there is not enough remaining data in `self`.
fn get_f64(&mut self) -> f64 {
f64::from_bits(Self::get_u64(self))
f64::from_bits(self.get_u64())
}

/// Gets an IEEE754 double-precision (8 bytes) floating point number from
Expand All @@ -1078,7 +1078,7 @@ pub trait Buf {
///
/// This function panics if there is not enough remaining data in `self`.
fn get_f64_le(&mut self) -> f64 {
f64::from_bits(Self::get_u64_le(self))
f64::from_bits(self.get_u64_le())
}

/// Gets an IEEE754 double-precision (8 bytes) floating point number from
Expand All @@ -1102,7 +1102,7 @@ pub trait Buf {
///
/// This function panics if there is not enough remaining data in `self`.
fn get_f64_ne(&mut self) -> f64 {
f64::from_bits(Self::get_u64_ne(self))
f64::from_bits(self.get_u64_ne())
}

/// Consumes `len` bytes inside self and returns new instance of `Bytes`
Expand All @@ -1120,6 +1120,10 @@ pub trait Buf {
/// let bytes = (&b"hello world"[..]).copy_to_bytes(5);
/// assert_eq!(&bytes[..], &b"hello"[..]);
/// ```
///
/// # Panics
///
/// This function panics if `len > self.remaining()`.
fn copy_to_bytes(&mut self, len: usize) -> crate::Bytes {
use super::BufMut;

Expand Down
4 changes: 1 addition & 3 deletions src/buf/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@ use std::io::IoSlice;
/// assert_eq!(full[..], b"hello world"[..]);
/// ```
///
/// [`Buf::chain`]: trait.Buf.html#method.chain
/// [`Buf`]: trait.Buf.html
/// [`BufMut`]: trait.BufMut.html
/// [`Buf::chain`]: Buf::chain
#[derive(Debug)]
pub struct Chain<T, U> {
a: T,
Expand Down
3 changes: 0 additions & 3 deletions src/buf/iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@ use crate::Buf;
/// assert_eq!(iter.next(), Some(b'c'));
/// assert_eq!(iter.next(), None);
/// ```
///
/// [`iter`]: trait.Buf.html#method.iter
/// [`Buf`]: trait.Buf.html
#[derive(Debug)]
pub struct IntoIter<T> {
inner: T,
Expand Down
2 changes: 0 additions & 2 deletions src/buf/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@
//! See [`Buf`] and [`BufMut`] for more details.
//!
//! [rope]: https://en.wikipedia.org/wiki/Rope_(data_structure)
//! [`Buf`]: trait.Buf.html
//! [`BufMut`]: trait.BufMut.html

mod buf_impl;
mod buf_mut;
Expand Down
2 changes: 1 addition & 1 deletion src/buf/reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::{cmp, io};
/// A `Buf` adapter which implements `io::Read` for the inner value.
///
/// This struct is generally created by calling `reader()` on `Buf`. See
/// documentation of [`reader()`](trait.Buf.html#method.reader) for more
/// documentation of [`reader()`](Buf::reader) for more
/// details.
#[derive(Debug)]
pub struct Reader<B> {
Expand Down
2 changes: 1 addition & 1 deletion src/buf/take.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use core::cmp;
/// A `Buf` adapter which limits the bytes read from an underlying buffer.
///
/// This struct is generally created by calling `take()` on `Buf`. See
/// documentation of [`take()`](trait.Buf.html#method.take) for more details.
/// documentation of [`take()`](Buf::take) for more details.
#[derive(Debug)]
pub struct Take<T> {
inner: T,
Expand Down
2 changes: 1 addition & 1 deletion src/buf/uninit_slice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ impl UninitSlice {
/// ```
#[inline]
pub unsafe fn as_uninit_slice_mut(&mut self) -> &mut [MaybeUninit<u8>] {
&mut *(self as *mut _ as *mut [MaybeUninit<u8>])
&mut self.0
}

/// Returns the number of bytes in the slice.
Expand Down
2 changes: 1 addition & 1 deletion src/buf/writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::{cmp, io};
/// A `BufMut` adapter which implements `io::Write` for the inner value.
///
/// This struct is generally created by calling `writer()` on `BufMut`. See
/// documentation of [`writer()`](trait.BufMut.html#method.writer) for more
/// documentation of [`writer()`](BufMut::writer) for more
/// details.
#[derive(Debug)]
pub struct Writer<B> {
Expand Down
Loading

0 comments on commit cd1401c

Please sign in to comment.