Skip to content

Commit 279b352

Browse files
committed
glib: Implement From<&GStr> and From<GString> for Cow<GStr>
1 parent 248aae9 commit 279b352

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

glib/src/gstring.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use crate::translate::*;
44
use crate::types::{StaticType, Type};
55
use crate::value::{FromValue, ToValue};
66
use crate::Value;
7-
use std::borrow::Borrow;
7+
use std::borrow::{Borrow, Cow};
88
use std::cmp::Ordering;
99
use std::ffi::{CStr, CString, OsStr};
1010
use std::fmt;
@@ -742,6 +742,18 @@ impl From<&CStr> for GString {
742742
}
743743
}
744744

745+
impl<'a> From<GString> for Cow<'a, GStr> {
746+
fn from(v: GString) -> Self {
747+
Cow::Owned(v)
748+
}
749+
}
750+
751+
impl<'a> From<&'a GStr> for Cow<'a, GStr> {
752+
fn from(v: &'a GStr) -> Self {
753+
Cow::Borrowed(v)
754+
}
755+
}
756+
745757
#[doc(hidden)]
746758
impl FromGlibPtrFull<*mut u8> for GString {
747759
#[inline]

0 commit comments

Comments
 (0)