From 294644d9f4857232ac094be8d99a8a5ab125c5a6 Mon Sep 17 00:00:00 2001 From: Jason Francis Date: Sun, 13 Mar 2022 12:00:12 -0400 Subject: [PATCH] glib: Add GString::from_utf8_unchecked --- glib/src/gstring.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/glib/src/gstring.rs b/glib/src/gstring.rs index 7b46e94c0a24..2606708eaa45 100644 --- a/glib/src/gstring.rs +++ b/glib/src/gstring.rs @@ -367,6 +367,12 @@ unsafe impl Send for GString {} unsafe impl Sync for GString {} impl GString { + // rustdoc-stripper-ignore-next + /// Creates a GLib string by consuming a byte vector, without checking for UTF-8 or interior 0 + /// bytes. Trailing 0 byte will be appended by this function. + pub unsafe fn from_utf8_unchecked(v: Vec) -> Self { + GString(Inner::Native(Some(CString::from_vec_unchecked(v)))) + } // rustdoc-stripper-ignore-next /// Return the `GString` as string slice. pub fn as_str(&self) -> &str {