gtk4/
string_object.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
// Take a look at the license at the top of the repository in the LICENSE file.

use glib::{GStr, GString};

use crate::StringObject;

impl From<StringObject> for String {
    #[inline]
    fn from(value: StringObject) -> Self {
        skip_assert_initialized!();
        Self::from(&value)
    }
}

impl From<StringObject> for GString {
    #[inline]
    fn from(value: StringObject) -> Self {
        skip_assert_initialized!();
        Self::from(&value)
    }
}

impl<'a> From<&'a StringObject> for String {
    #[inline]
    fn from(value: &'a StringObject) -> Self {
        skip_assert_initialized!();
        value.string().to_string()
    }
}

impl<'a> From<&'a StringObject> for GString {
    #[inline]
    fn from(value: &'a StringObject) -> Self {
        skip_assert_initialized!();
        value.string()
    }
}

impl From<String> for StringObject {
    #[inline]
    fn from(value: String) -> Self {
        skip_assert_initialized!();
        Self::new(&value)
    }
}

impl<'a> From<&'a String> for StringObject {
    #[inline]
    fn from(value: &'a String) -> Self {
        skip_assert_initialized!();
        Self::new(value)
    }
}

impl<'a> From<&'a GStr> for StringObject {
    #[inline]
    fn from(v: &'a GStr) -> Self {
        skip_assert_initialized!();
        Self::new(v)
    }
}

impl From<GString> for StringObject {
    #[inline]
    fn from(value: GString) -> Self {
        skip_assert_initialized!();
        Self::new(&value)
    }
}

impl<'a> From<&'a GString> for StringObject {
    #[inline]
    fn from(value: &'a GString) -> Self {
        skip_assert_initialized!();
        Self::new(value)
    }
}

impl From<&str> for StringObject {
    #[inline]
    fn from(value: &str) -> Self {
        skip_assert_initialized!();
        Self::new(value)
    }
}

#[cfg(test)]
mod tests {
    use super::StringObject;
    use crate as gtk4;

    #[test]
    fn from_into() {
        let obj = StringObject::new("some_str");
        assert_eq!(String::from(&obj), obj.string());
        assert_eq!(String::from(obj), "some_str");
    }
}