Skip to content

Commit

Permalink
Address review comments on documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
HeroicKatora committed Jul 25, 2019
1 parent fc7b254 commit 2581c4f
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,13 @@ pub unsafe fn concat<'a>(a: &'a str, b: &'a str) -> Result<&'a str, Error> {
/// than `isize::MAX`).
///
/// When T is a ZST then returns `Err(TooLong)` if the total length would overflow
/// `usize` and `Err(NotAdjacent)` otherwise.
/// `usize` and `Err(NotAdjacent)` otherwise. This is because ZST-slices are [extra
/// weird][zst-str-concat] and [their safety][zst-unsafe-wg1] is not yet [fully
/// determined][zst-unsafe-wg2].
///
/// [zst-str-concat]: https://github.com/oberien/str-concat/issues/5
/// [zst-unsafe-wg1]: https://github.com/rust-lang/unsafe-code-guidelines/issues/93
/// [zst-unsafe-wg2]: https://github.com/rust-lang/unsafe-code-guidelines/issues/168
///
/// # Safety
///
Expand Down Expand Up @@ -126,6 +132,10 @@ pub unsafe fn concat_slice<'a, T>(a: &'a [T], b: &'a [T]) -> Result<&'a [T], Err

// Never consider ZST slices adjacent. You could otherwise infinitely
// duplicate a non-zero length slice by concatenating it to itself.
// See: https://github.com/rust-lang/unsafe-code-guidelines/issues/93
// and https://github.com/rust-lang/unsafe-code-guidelines/issues/168
// where the second link makes it sound like it would be possible but
// not necessarily easy.
return Err(Error::NotAdjacent)
}

Expand Down Expand Up @@ -220,7 +230,7 @@ pub unsafe fn concat_unordered<'a>(a: &'a str, b: &'a str) -> Result<&'a str, Er
///
/// This is the same as [`concat_slice`] except that it also concatenates `b` to
/// `a` if `b` is in front of `a` (in which case of [`concat_slice`] errors).
/// Keep in mind that slices of ZSTs will still not be concatenated.
/// Keep in mind that slices of zero-sized types (ZST) will still not be concatenated.
///
/// # Safety
///
Expand All @@ -234,7 +244,7 @@ pub unsafe fn concat_unordered<'a>(a: &'a str, b: &'a str) -> Result<&'a str, Er
///
/// ```rust
/// # use str_concat::concat_slice_unordered;
/// let s = b"0123456789";
/// let s = [0, 1, 2, 3, 4, 5, 6];
/// unsafe {
/// // SAFETY: slices from the same bytes originally.
/// assert_eq!(b"0123456", concat_slice_unordered(&s[5..7], &s[..5]).unwrap());
Expand All @@ -245,7 +255,7 @@ pub unsafe fn concat_unordered<'a>(a: &'a str, b: &'a str) -> Result<&'a str, Er
///
/// ```rust
/// # use str_concat::{concat_slice_unordered, Error};
/// let s = b"0123456789";
/// let s = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
/// unsafe {
/// // SAFETY: slices from the same bytes originally.
/// assert_eq!(b"0123456", concat_slice_unordered(&s[..5], &s[5..7]).unwrap())
Expand Down

0 comments on commit 2581c4f

Please sign in to comment.