Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
The implementation for sizes higher than u16::MAX were unsound anyway.
- Added `shift_remove`, `shift_remove_entry` and `shift_remove_full` to `IndexMap` and `IndexSet`.
- Implemented `Index` and `IndexMut` for `Vec`.
- Made `String::from_utf8_unchecked` const. The v0.9.0 changelog already listed this, but the change was undone before that release.

## [v0.9.3] 2025-04-15

Expand Down
9 changes: 8 additions & 1 deletion src/string/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ impl<LenT: LenType, const N: usize> String<N, LenT> {
/// assert_eq!("💖", sparkle_heart);
/// ```
#[inline]
pub unsafe fn from_utf8_unchecked(vec: Vec<u8, N, LenT>) -> Self {
pub const unsafe fn from_utf8_unchecked(vec: Vec<u8, N, LenT>) -> Self {
Self { vec }
}

Expand Down Expand Up @@ -1116,6 +1116,13 @@ mod tests {
static mut _S: String<8> = String::new();
}

#[test]
fn static_from_utf8_unchecked() {
// SAFETY: `b"abcd"` is valid UTF-8.
static S: String<8> = unsafe { String::from_utf8_unchecked(Vec::from_array(*b"abcd")) };
assert_eq!(S, "abcd");
}

#[test]
fn clone() {
let s1: String<20> = String::try_from("abcd").unwrap();
Expand Down
Loading