Skip to content

Commit

Permalink
small formatting and doc updates
Browse files Browse the repository at this point in the history
  • Loading branch information
ParkMyCar committed May 27, 2022
1 parent 3baa256 commit 5934dfa
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 12 deletions.
4 changes: 2 additions & 2 deletions compact_str/src/features/bytes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ impl CompactString {
/// // `bytes::Buf` is implemented for `std::io::Cursor<&[u8]>`
/// let mut invalid = io::Cursor::new(&[0, 159]);
///
/// // The provided buffer is invalid, so trying to create a `ComapctStr` will fail
/// // The provided buffer is invalid, so trying to create a `CompactString` will fail
/// assert!(CompactString::from_utf8_buf(&mut invalid).is_err());
/// ```
pub fn from_utf8_buf<B: Buf>(buf: &mut B) -> Result<Self, Utf8Error> {
Expand All @@ -45,7 +45,7 @@ impl CompactString {
/// # Safety
/// This function is unsafe because it does not check that the provided bytes are valid UTF-8.
/// If this constraint is violated, it may cause memory safety issues with futures uses of the
/// `ComapctStr`, as the rest of the library assumes that `CompactString`s are valid UTF-8
/// `CompactString`, as the rest of the library assumes that `CompactString`s are valid UTF-8
///
/// # Examples
/// ```
Expand Down
4 changes: 2 additions & 2 deletions compact_str/src/features/serde.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use serde::de::{

use crate::CompactString;

fn compact_str<'de: 'a, 'a, D: Deserializer<'de>>(
fn compact_string<'de: 'a, 'a, D: Deserializer<'de>>(
deserializer: D,
) -> Result<CompactString, D::Error> {
struct CompactStringVisitor;
Expand Down Expand Up @@ -69,6 +69,6 @@ impl serde::Serialize for CompactString {

impl<'de> serde::Deserialize<'de> for CompactString {
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
compact_str(deserializer)
compact_string(deserializer)
}
}
3 changes: 1 addition & 2 deletions compact_str/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,6 @@ impl CompactString {
/// assert!(compact.is_heap_allocated());
/// assert!(compact.capacity() >= 200);
/// ```
#[inline]
pub fn reserve(&mut self, additional: usize) {
self.repr.reserve(additional)
Expand Down Expand Up @@ -429,7 +428,7 @@ impl CompactString {
}

/// Removes the last character from the [`CompactString`] and returns it.
/// Returns `None` if this `ComapctStr` is empty.
/// Returns `None` if this [`CompactString`] is empty.
///
/// # Examples
/// ```
Expand Down
14 changes: 8 additions & 6 deletions compact_str/src/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ use crate::CompactString;
/// A trait for converting a value to a `CompactString`.
///
/// This trait is automatically implemented for any type which implements the
/// [`fmt::Display`] trait. As such, `ToCompactString` shouldn't be implemented directly:
/// [`fmt::Display`] should be implemented instead, and you get the `ToCompactString`
/// [`fmt::Display`] trait. As such, [`ToCompactString`] shouldn't be implemented directly:
/// [`fmt::Display`] should be implemented instead, and you get the [`ToCompactString`]
/// implementation for free.
pub trait ToCompactString {
/// Converts the given value to a `CompactString`.
/// Converts the given value to a [`CompactString`].
///
/// # Examples
///
Expand All @@ -43,9 +43,10 @@ pub trait ToCompactString {

/// # Safety
///
/// * CompactString does not contain any lifetime
/// * CompactString is 'static
/// * CompactString is a container to `u8`, which is `LifetimeFree`.
/// * [`CompactString`] does not contain any lifetime
/// * [`CompactString`] is 'static
/// * [`CompactString`] is a container to `u8`, which is `LifetimeFree`.
///
unsafe impl LifetimeFree for CompactString {}
unsafe impl LifetimeFree for Repr {}

Expand All @@ -66,6 +67,7 @@ unsafe impl LifetimeFree for Repr {}
/// * `String`, `CompactString`
/// * `f32`, `f64`
/// * For floats we use [`ryu`] crate which sometimes provides different formatting than [`std`]
///
impl<T: fmt::Display> ToCompactString for T {
#[inline]
fn to_compact_string(&self) -> CompactString {
Expand Down

0 comments on commit 5934dfa

Please sign in to comment.