Skip to content

Commit

Permalink
Fix nightly warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
laurmaedje committed Sep 7, 2023
1 parent 200679b commit a729e38
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 18 deletions.
24 changes: 12 additions & 12 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,31 +29,31 @@ assert_eq!(third, "Welcome to earth! ");
## Why should I use this instead of ...
| Type | Details |
|:--------------------------------------------|:--------|
| [`Vec<T>`][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<Vec<T>>`][arc] / [`Arc<String>`][arc] | These require two allocations instead of one and are less convenient to mutate. |
| [`Arc<[T]>`][arc] / [`Arc<str>`][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<T>`]/ [`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<Vec<T>>`] / [`Arc<String>`] | These require two allocations instead of one and are less convenient to mutate. |
| [`Arc<[T]>`] / [`Arc<str>`] | 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)]
#![deny(missing_docs)]

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)]
Expand Down
5 changes: 2 additions & 3 deletions src/string.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -143,7 +142,7 @@ impl EcoString {
#[inline]
pub fn pop(&mut self) -> Option<char> {
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)
}
Expand Down
6 changes: 3 additions & 3 deletions src/vec.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -956,7 +956,7 @@ impl<T: Clone, const N: usize> From<[T; N]> for EcoVec<T> {
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
}
Expand All @@ -968,7 +968,7 @@ impl<T: Clone> From<Vec<T>> for EcoVec<T> {
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
}
Expand Down

0 comments on commit a729e38

Please sign in to comment.