Add `Safety` section to `ByteString::from_bytes_unchecked`

This commit is contained in:
Yuki Okushi 2020-07-22 10:00:48 +09:00
parent c14808e656
commit bf4c069624
No known key found for this signature in database
GPG Key ID: B0986C85C0E2DAA1
1 changed files with 7 additions and 0 deletions

View File

@ -33,6 +33,13 @@ impl ByteString {
}
/// Creates a new `ByteString` from a Bytes.
///
/// # Safety
/// This function is unsafe because it does not check the bytes passed to it
/// are valid UTF-8. If this constraint is violated,
/// it may cause memory unsafety issues with future users of the `ByteString`,
/// as we assume that `ByteString`s are valid UTF-8.
/// However, the most likely issue is that the data gets corrupted.
pub const unsafe fn from_bytes_unchecked(src: Bytes) -> ByteString {
Self(src)
}