From dffb7410d0337715a904241d6e23e8be76adcdac Mon Sep 17 00:00:00 2001 From: tormol Date: Sun, 20 Sep 2020 14:43:47 +0200 Subject: [PATCH 1/4] Constify AsciiStr.len() and AsciiStr.is_empty() slice.len() became const fn in Rust 1.39.0. --- src/ascii_str.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ascii_str.rs b/src/ascii_str.rs index 3c4dbf2..e8a6e12 100644 --- a/src/ascii_str.rs +++ b/src/ascii_str.rs @@ -139,7 +139,7 @@ impl AsciiStr { /// ``` #[inline] #[must_use] - pub fn len(&self) -> usize { + pub const fn len(&self) -> usize { self.slice.len() } @@ -155,7 +155,7 @@ impl AsciiStr { /// ``` #[inline] #[must_use] - pub fn is_empty(&self) -> bool { + pub const fn is_empty(&self) -> bool { self.len() == 0 } From f2c49911eb4777de2faead4686ab971a18d357da Mon Sep 17 00:00:00 2001 From: tormol Date: Fri, 10 Jun 2022 02:07:38 +0200 Subject: [PATCH 2/4] Convert Into<> impls to From<> impls A follop-up on #80 (commit 7b12e696b09281b4). --- src/ascii_string.rs | 43 ++++++++++++++++++------------------------- 1 file changed, 18 insertions(+), 25 deletions(-) diff --git a/src/ascii_string.rs b/src/ascii_string.rs index e85a512..10a88dc 100644 --- a/src/ascii_string.rs +++ b/src/ascii_string.rs @@ -497,16 +497,14 @@ impl From for AsciiString { } } -// FIXME? Turn this into a `From` impl -#[allow(clippy::from_over_into)] -impl Into> for AsciiString { - fn into(mut self) -> Vec { +impl From for Vec { + fn from(mut s: AsciiString) -> Vec { // SAFETY: All ascii bytes are valid `u8`, as we are `repr(u8)`. // Note: We forget `self` to avoid `self.vec` from being deallocated. - let ptr = self.vec.as_mut_ptr().cast::(); - let length = self.vec.len(); - let capacity = self.vec.capacity(); - mem::forget(self); + let ptr = s.vec.as_mut_ptr().cast::(); + let length = s.vec.len(); + let capacity = s.vec.capacity(); + mem::forget(s); // SAFETY: We guarantee all invariants due to getting `ptr`, `length` // and `capacity` from a `Vec`. We also guarantee `ptr` is valid @@ -515,10 +513,9 @@ impl Into> for AsciiString { } } -#[allow(clippy::from_over_into)] -impl Into> for AsciiString { - fn into(self) -> Vec { - self.vec +impl From for Vec { + fn from(s: AsciiString) -> Vec { + s.vec } } @@ -536,13 +533,11 @@ impl<'a> From<&'a [AsciiChar]> for AsciiString { } } -// FIXME? Turn this into a `From` impl -#[allow(clippy::from_over_into)] -impl Into for AsciiString { +impl From for String { #[inline] - fn into(self) -> String { + fn from(s: AsciiString) -> String { // SAFETY: All ascii bytes are `utf8`. - unsafe { String::from_utf8_unchecked(self.into()) } + unsafe { String::from_utf8_unchecked(s.into()) } } } @@ -560,19 +555,17 @@ impl From for Box { } } -#[allow(clippy::from_over_into)] -impl Into> for AsciiString { - fn into(self) -> Rc { - let var: Rc<[AsciiChar]> = self.vec.into(); +impl From for Rc { + fn from(s: AsciiString) -> Rc { + let var: Rc<[AsciiChar]> = s.vec.into(); // SAFETY: AsciiStr is repr(transparent) and thus has the same layout as [AsciiChar] unsafe { Rc::from_raw(Rc::into_raw(var) as *const AsciiStr) } } } -#[allow(clippy::from_over_into)] -impl Into> for AsciiString { - fn into(self) -> Arc { - let var: Arc<[AsciiChar]> = self.vec.into(); +impl From for Arc { + fn from(s: AsciiString) -> Arc { + let var: Arc<[AsciiChar]> = s.vec.into(); // SAFETY: AsciiStr is repr(transparent) and thus has the same layout as [AsciiChar] unsafe { Arc::from_raw(Arc::into_raw(var) as *const AsciiStr) } } From d8bb068d06d283047ac73100407ca76b602233f9 Mon Sep 17 00:00:00 2001 From: tormol Date: Sun, 5 Jun 2022 23:50:02 +0200 Subject: [PATCH 3/4] Delete .travis.yml No longer used. --- .travis.yml | 24 ------------------------ 1 file changed, 24 deletions(-) delete mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 49f82a1..0000000 --- a/.travis.yml +++ /dev/null @@ -1,24 +0,0 @@ -language: rust -cache: cargo -rust: - - 1.41.1 - - stable - - beta - - nightly - -jobs: - include: - - rust: nightly - name: "Test minimal dependency versions with Rust nightly" - script: cargo test -Zminimal-versions --verbose --all-features - - rust: stable - name: "Lint with Clippy" - install: rustup component add clippy - script: - - cargo clippy --verbose --all-targets --no-default-features - - cargo clippy --verbose --all-targets --all-features - -install: skip -script: - - cargo test --verbose --all-features - - cargo test --verbose --no-default-features From 7003127453aa94130a6ea66283a1e28eead6cbde Mon Sep 17 00:00:00 2001 From: tormol Date: Tue, 30 Aug 2022 00:50:21 +0200 Subject: [PATCH 4/4] Use SPDX license syntax --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 0956bb5..c09e985 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,7 +2,7 @@ authors = ["Thomas Bahn ", "Torbjørn Birch Moltu ", "Simon Sapin "] description = "ASCII-only equivalents to `char`, `str` and `String`." documentation = "https://docs.rs/ascii" -license = "Apache-2.0 / MIT" +license = "Apache-2.0 OR MIT" name = "ascii" readme = "README.md" repository = "https://github.com/tomprogrammer/rust-ascii"