Skip to content

Commit 94f97c2

Browse files
jf2048sdroege
authored andcommitted
glib: implement From<GStringPtr> for GString
1 parent 9903467 commit 94f97c2

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

glib/src/gstring.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1807,6 +1807,15 @@ impl From<&String> for GString {
18071807
}
18081808
}
18091809

1810+
impl From<GStringPtr> for GString {
1811+
#[inline]
1812+
fn from(s: GStringPtr) -> Self {
1813+
let s = mem::ManuallyDrop::new(s);
1814+
let len = unsafe { GStr::from_ptr(s.0.as_ptr()).len() };
1815+
GString(Inner::Foreign { ptr: s.0, len })
1816+
}
1817+
}
1818+
18101819
impl TryFrom<CString> for GString {
18111820
type Error = GStringUtf8Error<CString>;
18121821
#[inline]

0 commit comments

Comments
 (0)