Skip to content

Commit

Permalink
release: 0.1.7
Browse files Browse the repository at this point in the history
  • Loading branch information
joshstoik1 committed Jun 1, 2023
2 parents 7d19e80 + 1c0a0a8 commit d8b5ce7
Show file tree
Hide file tree
Showing 8 changed files with 106 additions and 93 deletions.
6 changes: 4 additions & 2 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ name: Build

on:
push:
branches: [ master ]
branches: []
pull_request:
branches: [ master ]
branches: []

defaults:
run:
Expand Down Expand Up @@ -51,6 +51,7 @@ jobs:
- name: Build
run: |
cargo build --target ${{ matrix.target }}
cargo build --release --target ${{ matrix.target }}
- name: Clippy
Expand All @@ -59,4 +60,5 @@ jobs:
- name: Tests
run: |
cargo test --target ${{ matrix.target }}
cargo test --release --target ${{ matrix.target }}
53 changes: 53 additions & 0 deletions .github/workflows/msrv.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
name: MSRV

on:
push:
branches: []
pull_request:
branches: []

defaults:
run:
shell: bash

env:
CARGO_TERM_COLOR: always

jobs:
all:
name: All

strategy:
matrix:
target:
- x86_64-unknown-linux-gnu
- x86_64-apple-darwin
include:
- target: x86_64-unknown-linux-gnu
os: ubuntu-latest
- target: x86_64-apple-darwin
os: macos-latest

runs-on: ${{matrix.os}}

env:
RUSTFLAGS: "-D warnings"

steps:
- uses: actions/checkout@v3
- uses: dtolnay/rust-toolchain@stable
with:
targets: ${{ matrix.target }}
- uses: taiki-e/install-action@v2
with:
tool: cargo-msrv

- name: Info
run: |
rustup --version
cargo --version
cargo clippy --version
- name: MSRV
run: |
cargo msrv verify
11 changes: 10 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,20 @@



## [0.1.7](https://github.com/Blobfolio/trimothy/releases/tag/v0.1.7) - 2023-06-01

### Changed

* Remove all `unsafe` blocks
* Improve CI coverage



## [0.1.6](https://github.com/Blobfolio/trimothy/releases/tag/v0.1.6) - 2023-01-26

### Changed

* Bump brunch `0.4`
* Bump brunch `0.4` (dev)



Expand Down
4 changes: 2 additions & 2 deletions CREDITS.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Project Dependencies
Package: trimothy
Version: 0.1.6
Generated: 2023-01-26 17:28:01 UTC
Version: 0.1.7
Generated: 2023-06-01 20:20:18 UTC

This package has no dependencies.
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "trimothy"
version = "0.1.6"
version = "0.1.7"
authors = ["Blobfolio, LLC. <[email protected]>"]
edition = "2021"
rust-version = "1.56"
Expand All @@ -25,7 +25,7 @@ man-dir = "./"
credits-dir = "./"

[dev-dependencies]
brunch = "0.4.*"
brunch = "0.5.*"

[[bench]]
name = "fn_trim_slice"
Expand Down
12 changes: 3 additions & 9 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,6 @@ bench BENCH="":
exit 0


# Check Release!
@check:
# First let's build the Rust bit.
cargo check \
--release \
--target x86_64-unknown-linux-gnu \
--target-dir "{{ cargo_dir }}"
# Clean Cargo crap.
@clean:
# Most things go here.
Expand Down Expand Up @@ -99,6 +90,9 @@ bench BENCH="":
# Unit tests!
@test:
clear
cargo test \
--target x86_64-unknown-linux-gnu \
--target-dir "{{ cargo_dir }}"
cargo test \
--release \
--target x86_64-unknown-linux-gnu \
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ trimothy = "0.1"
```
*/

#![deny(unsafe_code)]
#![forbid(unsafe_code)]

#![warn(
clippy::filetype_is_file,
Expand Down
107 changes: 31 additions & 76 deletions src/trim_mut.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ use alloc::{
string::String,
vec::Vec,
};
use core::intrinsics::copy;
use crate::{
not_whitespace,
TrimSlice,
Expand Down Expand Up @@ -108,33 +107,8 @@ pub trait TrimMatchesMut {



/// # Helper: String Trim.
macro_rules! string_trim {
($lhs:ident, $trimmed:expr) => (
let trimmed = $trimmed;
let trimmed_len = trimmed.len();

if trimmed_len < $lhs.len() {
if 0 < trimmed_len {
let trimmed_ptr = trimmed.as_ptr();

// Safety: we're just moving the trimmed portion to the start
// of the buffer and chopping the length to match.
unsafe {
let v = $lhs.as_mut_vec();
copy(trimmed_ptr, v.as_mut_ptr(), trimmed_len);
v.set_len(trimmed_len);
}
}
else { $lhs.truncate(0); }
}
);
}



impl TrimMut for String {
#[allow(unsafe_code)]
#[inline]
/// # Trim Mut.
///
/// Remove leading and trailing whitespace, mutably.
Expand All @@ -148,9 +122,11 @@ impl TrimMut for String {
/// s.trim_mut();
/// assert_eq!(s, "Hello World!");
/// ```
fn trim_mut(&mut self) { string_trim!(self, self.trim()); }
fn trim_mut(&mut self) {
self.trim_matches_mut(char::is_whitespace);
}

#[allow(unsafe_code)]
#[inline]
/// # Trim Start Mut.
///
/// Remove leading whitespace, mutably.
Expand All @@ -164,8 +140,11 @@ impl TrimMut for String {
/// s.trim_start_mut();
/// assert_eq!(s, "Hello World! ");
/// ```
fn trim_start_mut(&mut self) { string_trim!(self, self.trim_start()); }
fn trim_start_mut(&mut self) {
self.trim_start_matches_mut(char::is_whitespace);
}

#[inline]
/// # Trim End Mut.
///
/// Remove trailing whitespace, mutably.
Expand All @@ -180,16 +159,13 @@ impl TrimMut for String {
/// assert_eq!(s, " Hello World!");
/// ```
fn trim_end_mut(&mut self) {
let trimmed = self.trim_end();
let trimmed_len = trimmed.len();
self.truncate(trimmed_len);
self.trim_end_matches_mut(char::is_whitespace);
}
}

impl TrimMatchesMut for String {
type MatchUnit = char;

#[allow(unsafe_code)]
/// # Trim Matches Mut.
///
/// Trim arbitrary leading and trailing bytes as determined by the provided
Expand All @@ -206,9 +182,11 @@ impl TrimMatchesMut for String {
/// assert_eq!(s, "ello World!");
/// ```
fn trim_matches_mut<F>(&mut self, cb: F)
where F: Fn(Self::MatchUnit) -> bool { string_trim!(self, self.trim_matches(cb)); }
where F: Fn(Self::MatchUnit) -> bool {
self.trim_end_matches_mut(&cb);
self.trim_start_matches_mut(cb);
}

#[allow(unsafe_code)]
/// # Trim Start Matches Mut.
///
/// Trim arbitrary leading bytes as determined by the provided callback,
Expand All @@ -226,7 +204,10 @@ impl TrimMatchesMut for String {
/// ```
fn trim_start_matches_mut<F>(&mut self, cb: F)
where F: Fn(Self::MatchUnit) -> bool {
string_trim!(self, self.trim_start_matches(cb));
if let Some(start) = self.find(|c| ! cb(c)) {
if start != 0 { self.drain(..start); }
}
else { self.truncate(0); }
}

/// # Trim End Matches Mut.
Expand All @@ -246,9 +227,10 @@ impl TrimMatchesMut for String {
/// ```
fn trim_end_matches_mut<F>(&mut self, cb: F)
where F: Fn(Self::MatchUnit) -> bool {
let trimmed = self.trim_end_matches(cb);
let trimmed_len = trimmed.len();
self.truncate(trimmed_len);
if let Some(end) = self.rfind(|c| ! cb(c)) {
self.truncate(end + 1);
}
else { self.truncate(0); }
}
}

Expand Down Expand Up @@ -397,11 +379,10 @@ impl TrimMut for Vec<u8> {
/// assert_eq!(v, b"Hello World!");
/// ```
fn trim_mut(&mut self) {
self.trim_start_mut();
self.trim_end_mut();
self.trim_start_mut();
}

#[allow(unsafe_code)]
/// # Trim Start Mut.
///
/// Remove leading (ASCII) whitespace, mutably.
Expand All @@ -417,15 +398,10 @@ impl TrimMut for Vec<u8> {
/// ```
fn trim_start_mut(&mut self) {
if let Some(start) = self.iter().position(not_whitespace) {
if 0 < start {
if 0 != start {
let trimmed_len = self.len() - start;

// Safety: we're just moving the trimmed portion to the start
// of the buffer and chopping the length to match.
unsafe {
copy(self.as_ptr().add(start), self.as_mut_ptr(), trimmed_len);
self.set_len(trimmed_len);
}
self.copy_within(start.., 0);
self.truncate(trimmed_len);
}
}
else { self.truncate(0); }
Expand Down Expand Up @@ -455,7 +431,6 @@ impl TrimMut for Vec<u8> {
impl TrimMatchesMut for Vec<u8> {
type MatchUnit = u8;

#[allow(unsafe_code)]
/// # Trim Matches Mut.
///
/// Trim arbitrary leading and trailing bytes as determined by the provided
Expand All @@ -473,25 +448,10 @@ impl TrimMatchesMut for Vec<u8> {
/// ```
fn trim_matches_mut<F>(&mut self, cb: F)
where F: Fn(Self::MatchUnit) -> bool {
let trimmed = self.trim_matches(cb);
let trimmed_len = trimmed.len();

if trimmed_len < self.len() {
if 0 < trimmed_len {
let trimmed_ptr = trimmed.as_ptr();

// Safety: we're just moving the trimmed portion to the start
// of the buffer and chopping the length to match.
unsafe {
copy(trimmed_ptr, self.as_mut_ptr(), trimmed_len);
self.set_len(trimmed_len);
}
}
else { self.truncate(0); }
}
self.trim_end_matches_mut(&cb);
self.trim_start_matches_mut(cb);
}

#[allow(unsafe_code)]
/// # Trim Start Matches Mut.
///
/// Trim arbitrary leading bytes as determined by the provided callback,
Expand All @@ -510,15 +470,10 @@ impl TrimMatchesMut for Vec<u8> {
fn trim_start_matches_mut<F>(&mut self, cb: F)
where F: Fn(Self::MatchUnit) -> bool {
if let Some(start) = self.iter().position(|b: &u8| ! cb(*b)) {
if 0 < start {
if 0 != start {
let trimmed_len = self.len() - start;

// Safety: we're just moving the trimmed portion to the start
// of the buffer and chopping the length to match.
unsafe {
copy(self.as_ptr().add(start), self.as_mut_ptr(), trimmed_len);
self.set_len(trimmed_len);
}
self.copy_within(start.., 0);
self.truncate(trimmed_len);
}
}
else { self.truncate(0); }
Expand Down

0 comments on commit d8b5ce7

Please sign in to comment.