From bf4c0696247ca08cb9db0593a8c0ad6ea103c3d5 Mon Sep 17 00:00:00 2001 From: Yuki Okushi Date: Wed, 22 Jul 2020 10:00:48 +0900 Subject: [PATCH] Add `Safety` section to `ByteString::from_bytes_unchecked` --- string/src/lib.rs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/string/src/lib.rs b/string/src/lib.rs index 7695c6fc..dd89399b 100644 --- a/string/src/lib.rs +++ b/string/src/lib.rs @@ -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) }