mirror of
https://github.com/fafhrd91/actix-net
synced 2024-11-24 13:52:59 +01:00
feat(bytestring): split_at method (#619)
This commit is contained in:
parent
47f0017899
commit
0e36c5f5c4
30
.github/workflows/lint.yml
vendored
30
.github/workflows/lint.yml
vendored
@ -40,7 +40,7 @@ jobs:
|
|||||||
|
|
||||||
- uses: giraffate/clippy-action@v1.0.1
|
- uses: giraffate/clippy-action@v1.0.1
|
||||||
with:
|
with:
|
||||||
reporter: 'github-pr-check'
|
reporter: "github-pr-check"
|
||||||
github_token: ${{ secrets.GITHUB_TOKEN }}
|
github_token: ${{ secrets.GITHUB_TOKEN }}
|
||||||
clippy_flags: --workspace --all-features --tests --examples --bins -- -Dclippy::todo -Aunknown_lints
|
clippy_flags: --workspace --all-features --tests --examples --bins -- -Dclippy::todo -Aunknown_lints
|
||||||
|
|
||||||
@ -67,3 +67,31 @@ jobs:
|
|||||||
|
|
||||||
- name: check external types
|
- name: check external types
|
||||||
run: just check-external-types-all +${{ vars.RUST_VERSION_EXTERNAL_TYPES }}
|
run: just check-external-types-all +${{ vars.RUST_VERSION_EXTERNAL_TYPES }}
|
||||||
|
|
||||||
|
public-api-diff:
|
||||||
|
name: Public API Diff
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Checkout main branch
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
ref: ${{ github.base_ref }}
|
||||||
|
|
||||||
|
- name: Checkout PR branch
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Install Rust (${{ vars.RUST_VERSION_API_DIFF }})
|
||||||
|
uses: actions-rust-lang/setup-rust-toolchain@v1.8.0
|
||||||
|
with:
|
||||||
|
toolchain: ${{ vars.RUST_VERSION_API_DIFF }}
|
||||||
|
|
||||||
|
- name: Install cargo-public-api
|
||||||
|
uses: taiki-e/install-action@v2.34.0
|
||||||
|
with:
|
||||||
|
tool: cargo-public-api
|
||||||
|
|
||||||
|
- name: Generate API diff
|
||||||
|
run: |
|
||||||
|
for f in $(find -mindepth 2 -maxdepth 2 -name Cargo.toml); do
|
||||||
|
cargo public-api --manifest-path "$f" --simplified diff ${{ github.event.pull_request.base.sha }}..${{ github.sha }}
|
||||||
|
done
|
||||||
|
@ -17,7 +17,7 @@ members = [
|
|||||||
[workspace.package]
|
[workspace.package]
|
||||||
license = "MIT OR Apache-2.0"
|
license = "MIT OR Apache-2.0"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
rust-version = "1.70"
|
rust-version = "1.71.1"
|
||||||
|
|
||||||
[patch.crates-io]
|
[patch.crates-io]
|
||||||
actix-codec = { path = "actix-codec" }
|
actix-codec = { path = "actix-codec" }
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
## Unreleased
|
## Unreleased
|
||||||
|
|
||||||
- Minimum supported Rust version (MSRV) is now 1.70.
|
- Minimum supported Rust version (MSRV) is now 1.71.
|
||||||
|
|
||||||
## 0.5.2
|
## 0.5.2
|
||||||
|
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
## Unreleased
|
## Unreleased
|
||||||
|
|
||||||
- Minimum supported Rust version (MSRV) is now 1.70.
|
- Minimum supported Rust version (MSRV) is now 1.71.
|
||||||
|
|
||||||
## 0.2.4
|
## 0.2.4
|
||||||
|
|
||||||
|
@ -2,6 +2,8 @@
|
|||||||
|
|
||||||
## Unreleased
|
## Unreleased
|
||||||
|
|
||||||
|
- Minimum supported Rust version (MSRV) is now 1.71.
|
||||||
|
|
||||||
## 2.10.0
|
## 2.10.0
|
||||||
|
|
||||||
- Relax `F`'s bound (`Fn => FnOnce`) on `{Arbiter, System}::with_tokio_rt()` functions.
|
- Relax `F`'s bound (`Fn => FnOnce`) on `{Arbiter, System}::with_tokio_rt()` functions.
|
||||||
|
@ -2,6 +2,8 @@
|
|||||||
|
|
||||||
## Unreleased
|
## Unreleased
|
||||||
|
|
||||||
|
- Minimum supported Rust version (MSRV) is now 1.71.
|
||||||
|
|
||||||
## 2.5.0
|
## 2.5.0
|
||||||
|
|
||||||
- Update `mio` dependency to `1`.
|
- Update `mio` dependency to `1`.
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
## Unreleased
|
## Unreleased
|
||||||
|
|
||||||
- Minimum supported Rust version (MSRV) is now 1.70.
|
- Minimum supported Rust version (MSRV) is now 1.71.
|
||||||
|
|
||||||
## 2.0.2
|
## 2.0.2
|
||||||
|
|
||||||
|
@ -2,6 +2,8 @@
|
|||||||
|
|
||||||
## Unreleased
|
## Unreleased
|
||||||
|
|
||||||
|
- Minimum supported Rust version (MSRV) is now 1.71.
|
||||||
|
|
||||||
## 3.4.0
|
## 3.4.0
|
||||||
|
|
||||||
- Add `rustls-0_23`, `rustls-0_23-webpki-roots`, and `rustls-0_23-native-roots` crate features.
|
- Add `rustls-0_23`, `rustls-0_23-webpki-roots`, and `rustls-0_23-native-roots` crate features.
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
## Unreleased
|
## Unreleased
|
||||||
|
|
||||||
- Minimum supported Rust version (MSRV) is now 1.70.
|
- Minimum supported Rust version (MSRV) is now 1.71.
|
||||||
|
|
||||||
## 0.1.0
|
## 0.1.0
|
||||||
|
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
## Unreleased
|
## Unreleased
|
||||||
|
|
||||||
- Minimum supported Rust version (MSRV) is now 1.70.
|
- Minimum supported Rust version (MSRV) is now 1.71.
|
||||||
|
|
||||||
## 3.0.1
|
## 3.0.1
|
||||||
|
|
||||||
|
@ -2,7 +2,10 @@
|
|||||||
|
|
||||||
## Unreleased
|
## Unreleased
|
||||||
|
|
||||||
- Minimum supported Rust version (MSRV) is now 1.70.
|
## 1.4.0
|
||||||
|
|
||||||
|
- Add `ByteString::split_at()` method.
|
||||||
|
- Minimum supported Rust version (MSRV) is now 1.71.
|
||||||
|
|
||||||
## 1.3.1
|
## 1.3.1
|
||||||
|
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "bytestring"
|
name = "bytestring"
|
||||||
version = "1.3.1"
|
version = "1.4.0"
|
||||||
description = "A UTF-8 encoded read-only string using `Bytes` as storage"
|
description = "A UTF-8 encoded read-only string using `Bytes` as storage"
|
||||||
authors = [
|
authors = [
|
||||||
"Nikolay Kim <fafhrd91@gmail.com>",
|
"Nikolay Kim <fafhrd91@gmail.com>",
|
||||||
"Rob Ede <robjtede@icloud.com>",
|
"Rob Ede <robjtede@icloud.com>",
|
||||||
]
|
]
|
||||||
keywords = ["string", "bytes", "utf8", "web", "actix"]
|
keywords = ["string", "bytes", "utf8", "web", "bytestring"]
|
||||||
categories = ["no-std", "web-programming"]
|
categories = ["no-std", "web-programming"]
|
||||||
homepage = "https://actix.rs"
|
homepage = "https://actix.rs"
|
||||||
repository = "https://github.com/actix/actix-net"
|
repository = "https://github.com/actix/actix-net"
|
||||||
|
@ -5,11 +5,11 @@
|
|||||||
<!-- prettier-ignore-start -->
|
<!-- prettier-ignore-start -->
|
||||||
|
|
||||||
[![crates.io](https://img.shields.io/crates/v/bytestring?label=latest)](https://crates.io/crates/bytestring)
|
[![crates.io](https://img.shields.io/crates/v/bytestring?label=latest)](https://crates.io/crates/bytestring)
|
||||||
[![Documentation](https://docs.rs/bytestring/badge.svg?version=1.3.1)](https://docs.rs/bytestring/1.3.1)
|
[![Documentation](https://docs.rs/bytestring/badge.svg?version=1.4.0)](https://docs.rs/bytestring/1.4.0)
|
||||||
[![Version](https://img.shields.io/badge/rustc-1.52+-ab6000.svg)](https://blog.rust-lang.org/2021/05/06/Rust-1.52.0.html)
|
[![Version](https://img.shields.io/badge/rustc-1.52+-ab6000.svg)](https://blog.rust-lang.org/2021/05/06/Rust-1.52.0.html)
|
||||||
![MIT or Apache 2.0 licensed](https://img.shields.io/crates/l/bytestring.svg)
|
![MIT or Apache 2.0 licensed](https://img.shields.io/crates/l/bytestring.svg)
|
||||||
<br />
|
<br />
|
||||||
[![Dependency Status](https://deps.rs/crate/bytestring/1.3.1/status.svg)](https://deps.rs/crate/bytestring/1.3.1)
|
[![Dependency Status](https://deps.rs/crate/bytestring/1.4.0/status.svg)](https://deps.rs/crate/bytestring/1.4.0)
|
||||||
![Download](https://img.shields.io/crates/d/bytestring.svg)
|
![Download](https://img.shields.io/crates/d/bytestring.svg)
|
||||||
[![Chat on Discord](https://img.shields.io/discord/771444961383153695?label=chat&logo=discord)](https://discord.gg/NWpN5mmg3x)
|
[![Chat on Discord](https://img.shields.io/discord/771444961383153695?label=chat&logo=discord)](https://discord.gg/NWpN5mmg3x)
|
||||||
|
|
||||||
|
@ -17,7 +17,7 @@ use core::{borrow::Borrow, fmt, hash, ops, str};
|
|||||||
|
|
||||||
use bytes::Bytes;
|
use bytes::Bytes;
|
||||||
|
|
||||||
/// An immutable UTF-8 encoded string with [`Bytes`] as a storage.
|
/// An immutable UTF-8 encoded string using [`Bytes`] as the storage.
|
||||||
#[derive(Clone, Default, Eq, PartialOrd, Ord)]
|
#[derive(Clone, Default, Eq, PartialOrd, Ord)]
|
||||||
pub struct ByteString(Bytes);
|
pub struct ByteString(Bytes);
|
||||||
|
|
||||||
@ -53,7 +53,29 @@ impl ByteString {
|
|||||||
Self(src)
|
Self(src)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns a new byte string that is equivalent to the given `subset`.
|
/// Divides one bytestring into two at an index, returning both parts.
|
||||||
|
///
|
||||||
|
/// # Panics
|
||||||
|
///
|
||||||
|
/// Panics if `mid` is not on a UTF-8 code point boundary, or if it is past the end of the last
|
||||||
|
/// code point of the bytestring.
|
||||||
|
pub fn split_at(&self, mid: usize) -> (ByteString, ByteString) {
|
||||||
|
let this: &str = self.as_ref();
|
||||||
|
let _valid_midpoint_check = this.split_at(mid);
|
||||||
|
|
||||||
|
let mut bytes = self.0.clone();
|
||||||
|
let first = bytes.split_to(mid);
|
||||||
|
let last = bytes;
|
||||||
|
|
||||||
|
unsafe {
|
||||||
|
(
|
||||||
|
ByteString::from_bytes_unchecked(first),
|
||||||
|
ByteString::from_bytes_unchecked(last),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Returns a new `ByteString` that is equivalent to the given `subset`.
|
||||||
///
|
///
|
||||||
/// When processing a `ByteString` buffer with other tools, one often gets a `&str` which is in
|
/// When processing a `ByteString` buffer with other tools, one often gets a `&str` which is in
|
||||||
/// fact a slice of the original `ByteString`; i.e., a subset of it. This function turns that
|
/// fact a slice of the original `ByteString`; i.e., a subset of it. This function turns that
|
||||||
@ -465,4 +487,33 @@ mod test {
|
|||||||
// being a logical subset of the string
|
// being a logical subset of the string
|
||||||
ByteString::from_static("foo bar").slice_ref("foo");
|
ByteString::from_static("foo bar").slice_ref("foo");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn split_at() {
|
||||||
|
let buf = ByteString::from_static("foo bar");
|
||||||
|
|
||||||
|
let (first, last) = buf.split_at(0);
|
||||||
|
assert_eq!(ByteString::from_static(""), first);
|
||||||
|
assert_eq!(ByteString::from_static("foo bar"), last);
|
||||||
|
|
||||||
|
let (first, last) = buf.split_at(4);
|
||||||
|
assert_eq!(ByteString::from_static("foo "), first);
|
||||||
|
assert_eq!(ByteString::from_static("bar"), last);
|
||||||
|
|
||||||
|
let (first, last) = buf.split_at(7);
|
||||||
|
assert_eq!(ByteString::from_static("foo bar"), first);
|
||||||
|
assert_eq!(ByteString::from_static(""), last);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
#[should_panic = "byte index 1 is not a char boundary;"]
|
||||||
|
fn split_at_invalid_code_point() {
|
||||||
|
ByteString::from_static("µ").split_at(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
#[should_panic = "byte index 9 is out of bounds"]
|
||||||
|
fn split_at_outside_string() {
|
||||||
|
ByteString::from_static("foo").split_at(9);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
## Unreleased
|
## Unreleased
|
||||||
|
|
||||||
- Minimum supported Rust version (MSRV) is now 1.70.
|
- Minimum supported Rust version (MSRV) is now 1.71.
|
||||||
|
|
||||||
## 0.1.5
|
## 0.1.5
|
||||||
|
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
## Unreleased
|
## Unreleased
|
||||||
|
|
||||||
- Minimum supported Rust version (MSRV) is now 1.70.
|
- Minimum supported Rust version (MSRV) is now 1.71.
|
||||||
|
|
||||||
## 0.1.4
|
## 0.1.4
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user