Skip to content

Commit 95ba278

Browse files
committed
Add a callable memory layout validator, and clean up docs.
1 parent 1040ba0 commit 95ba278

File tree

5 files changed

+122
-114
lines changed

5 files changed

+122
-114
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,13 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project
66
adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
77

8+
## [Unreleased]
9+
10+
### ADDED
11+
12+
- You can (and should) now call `smartstring::validate()` from your own code or test suite to
13+
validate `SmartString`'s memory layout assumptions.
14+
815
## [0.2.8] - 2021-07-26
916

1017
### CHANGED

src/config.rs

Lines changed: 13 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -7,47 +7,38 @@ use alloc::string::String;
77
use core::mem::{align_of, size_of};
88
use static_assertions::{assert_cfg, assert_eq_size, const_assert, const_assert_eq};
99

10-
/// A compact string representation equal to [`String`][String] in size with guaranteed inlining.
10+
/// A compact string representation equal to [`String`] in size with guaranteed inlining.
1111
///
1212
/// This representation relies on pointer alignment to be able to store a discriminant bit in its
13-
/// inline form that will never be present in its [`String`][String] form, thus
13+
/// inline form that will never be present in its [`String`] form, thus
1414
/// giving us 24 bytes on 64-bit architectures, and 12 bytes on 32-bit, minus one bit, to encode our
1515
/// inline string. It uses the rest of the discriminant bit's byte to encode the string length, and
1616
/// the remaining bytes (23 or 11 depending on arch) to store the string data. When the available space is exceeded,
17-
/// it swaps itself out with a [`String`][String] containing its previous
18-
/// contents, relying on the discriminant bit in the [`String`][String]'s pointer to be unset, so we can
19-
/// store the [`String`][String] safely without taking up any extra space for a discriminant.
17+
/// it swaps itself out with a [`String`] containing its previous
18+
/// contents, relying on the discriminant bit in the [`String`]'s pointer to be unset, so we can
19+
/// store the [`String`] safely without taking up any extra space for a discriminant.
2020
///
21-
/// This performs generally as well as [`String`][String] on all ops on boxed strings, and
22-
/// better than [`String`][String]s on inlined strings.
23-
///
24-
/// [String]: https://doc.rust-lang.org/std/string/struct.String.html
21+
/// This performs generally as well as [`String`] on all ops on boxed strings, and
22+
/// better than [`String`]s on inlined strings.
2523
#[derive(Debug)]
2624
pub struct Compact;
2725

28-
/// A representation similar to [`Compact`][Compact] but which doesn't re-inline strings.
26+
/// A representation similar to [`Compact`] but which doesn't re-inline strings.
2927
///
30-
/// This is a variant of [`Compact`][Compact] which doesn't aggressively inline strings.
31-
/// Where [`Compact`][Compact] automatically turns a heap allocated string back into an
32-
/// inlined string if it should become short enough, [`LazyCompact`][LazyCompact] keeps
28+
/// This is a variant of [`Compact`] which doesn't aggressively inline strings.
29+
/// Where [`Compact`] automatically turns a heap allocated string back into an
30+
/// inlined string if it should become short enough, [`LazyCompact`] keeps
3331
/// it heap allocated once heap allocation has occurred. If your aim is to defer heap
3432
/// allocation as much as possible, rather than to ensure cache locality, this is the
3533
/// variant you want - it won't allocate until the inline capacity is exceeded, and it
3634
/// also won't deallocate once allocation has occurred, which risks reallocation if the
3735
/// string exceeds its inline capacity in the future.
38-
///
39-
/// [Compact]: struct.Compact.html
40-
/// [String]: https://doc.rust-lang.org/std/string/struct.String.html
4136
#[derive(Debug)]
4237
pub struct LazyCompact;
4338

44-
/// Marker trait for [`SmartString`][SmartString] representations.
45-
///
46-
/// See [`LazyCompact`][LazyCompact] and [`Compact`][Compact].
39+
/// Marker trait for [`SmartString`] representations.
4740
///
48-
/// [SmartString]: struct.SmartString.html
49-
/// [Compact]: struct.Compact.html
50-
/// [LazyCompact]: struct.LazyCompact.html
41+
/// See [`LazyCompact`] and [`Compact`].
5142
pub trait SmartStringMode {
5243
/// The boxed string type for this layout.
5344
type BoxedString: BoxedString + From<String>;

src/iter.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@ use core::{
77
str::Chars,
88
};
99

10-
/// A draining iterator for a [`SmartString`][SmartString].
11-
///
12-
/// [SmartString]: struct.SmartString.html
10+
/// A draining iterator for a [`SmartString`].
1311
pub struct Drain<'a, Mode>(DrainCast<'a, Mode>)
1412
where
1513
Mode: SmartStringMode;

0 commit comments

Comments
 (0)