From a729e3877ed6e567bbaefc6fa28f22a2ba6ecaf0 Mon Sep 17 00:00:00 2001 From: Laurenz Date: Thu, 7 Sep 2023 12:22:55 +0200 Subject: [PATCH] Fix nightly warnings --- src/lib.rs | 24 ++++++++++++------------ src/string.rs | 5 ++--- src/vec.rs | 6 +++--- 3 files changed, 17 insertions(+), 18 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index ddd343e..f709ff5 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -29,17 +29,13 @@ assert_eq!(third, "Welcome to earth! "); ## Why should I use this instead of ... -| Type | Details | -|:--------------------------------------------|:--------| -| [`Vec`][vec] / [`String`][string] | Normal vectors are a great general purpose data structure. But they have a quite big footprint (3 machine words) and are expensive to clone. The [`EcoVec`] has a bit of overhead for mutation, but is cheap to clone and only takes two words. | -| [`Arc>`][arc] / [`Arc`][arc] | These require two allocations instead of one and are less convenient to mutate. | -| [`Arc<[T]>`][arc] / [`Arc`][arc] | While these require only one allocation, they aren't mutable. | -| Small vector | Different trade-off. Great when there are few, small `T`s, but expensive to clone when spilled to the heap. | -| Small string | The [`EcoString`] combines different small string qualities into a very practical package: It has inline storage, a smaller footprint than a normal [`String`][string], is efficient to clone even when spilled, and at the same time mutable. | - -[arc]: alloc::sync::Arc -[string]: alloc::string::String -[vec]: alloc::vec::Vec +| Type | Details | +|:----------------------------------|:--------| +| [`Vec`]/ [`String`] | Normal vectors are a great general purpose data structure. But they have a quite big footprint (3 machine words) and are expensive to clone. The [`EcoVec`] has a bit of overhead for mutation, but is cheap to clone and only takes two words. | +| [`Arc>`] / [`Arc`] | These require two allocations instead of one and are less convenient to mutate. | +| [`Arc<[T]>`] / [`Arc`] | While these require only one allocation, they aren't mutable. | +| Small vector | Different trade-off. Great when there are few, small `T`s, but expensive to clone when spilled to the heap. | +| Small string | The [`EcoString`] combines different small string qualities into a very practical package: It has inline storage, a smaller footprint than a normal [`String`][string], is efficient to clone even when spilled, and at the same time mutable. | */ #![cfg_attr(not(feature = "std"), no_std)] @@ -47,13 +43,17 @@ assert_eq!(third, "Welcome to earth! "); extern crate alloc; -mod dynamic; pub mod string; pub mod vec; +mod dynamic; + pub use self::string::EcoString; pub use self::vec::EcoVec; +#[cfg(doc)] +use alloc::{string::String, sync::Arc, vec::Vec}; + // Run doctests on the README too #[doc = include_str!("../README.md")] #[cfg(doctest)] diff --git a/src/string.rs b/src/string.rs index bd6fa70..04fcd3f 100644 --- a/src/string.rs +++ b/src/string.rs @@ -1,5 +1,4 @@ -//! A clone-on-write, small-string-optimized alternative to -//! [`String`][alloc::string::String]. +//! A clone-on-write, small-string-optimized alternative to [`String`]. use alloc::borrow::Cow; use alloc::string::String; @@ -143,7 +142,7 @@ impl EcoString { #[inline] pub fn pop(&mut self) -> Option { let slice = self.as_str(); - let c = slice.chars().rev().next()?; + let c = slice.chars().next_back()?; self.0.truncate(slice.len() - c.len_utf8()); Some(c) } diff --git a/src/vec.rs b/src/vec.rs index aa08d12..0f99ea7 100644 --- a/src/vec.rs +++ b/src/vec.rs @@ -1,4 +1,4 @@ -//! A clone-on-write alternative to [`Vec`][alloc::vec::Vec]. +//! A clone-on-write alternative to [`Vec`]. use alloc::vec::Vec; use core::alloc::Layout; @@ -956,7 +956,7 @@ impl From<[T; N]> for EcoVec { let mut vec = Self::new(); unsafe { // Safety: Array's IntoIter implements `TrustedLen`. - vec.extend_from_trusted(array.len(), array.into_iter()); + vec.extend_from_trusted(array.len(), array); } vec } @@ -968,7 +968,7 @@ impl From> for EcoVec { let mut vec = Self::new(); unsafe { // Safety: Vec's IntoIter implements `TrustedLen`. - vec.extend_from_trusted(other.len(), other.into_iter()); + vec.extend_from_trusted(other.len(), other); } vec }