Skip to content

Commit a88d2ed

Browse files
authored
Merge pull request #926 from pbor/key_file
Use `PtrSlice<GStrPtr>` for `KeyFile` methods
2 parents 6341060 + 1918b66 commit a88d2ed

File tree

3 files changed

+44
-39
lines changed

3 files changed

+44
-39
lines changed

glib/Gir.toml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -612,6 +612,14 @@ status = "generate"
612612
#wrong array type
613613
ignore = true
614614
[[object.function]]
615+
name = "get_groups"
616+
#return slice of str pointers
617+
manual = true
618+
[[object.function]]
619+
name = "get_keys"
620+
#return slice of str pointers
621+
manual = true
622+
[[object.function]]
615623
name = "get_boolean"
616624
#boolean return value needs to be returned
617625
manual = true

glib/src/auto/key_file.rs

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -88,19 +88,6 @@ impl KeyFile {
8888
}
8989
}
9090

91-
#[doc(alias = "g_key_file_get_groups")]
92-
#[doc(alias = "get_groups")]
93-
pub fn groups(&self) -> (Vec<crate::GString>, usize) {
94-
unsafe {
95-
let mut length = mem::MaybeUninit::uninit();
96-
let ret = FromGlibPtrContainer::from_glib_full(ffi::g_key_file_get_groups(
97-
self.to_glib_none().0,
98-
length.as_mut_ptr(),
99-
));
100-
(ret, length.assume_init())
101-
}
102-
}
103-
10491
#[doc(alias = "g_key_file_get_int64")]
10592
#[doc(alias = "get_int64")]
10693
pub fn int64(&self, group_name: &str, key: &str) -> Result<i64, crate::Error> {
@@ -163,29 +150,6 @@ impl KeyFile {
163150
}
164151
}
165152

166-
#[doc(alias = "g_key_file_get_keys")]
167-
#[doc(alias = "get_keys")]
168-
pub fn keys(&self, group_name: &str) -> Result<(Vec<crate::GString>, usize), crate::Error> {
169-
unsafe {
170-
let mut length = mem::MaybeUninit::uninit();
171-
let mut error = ptr::null_mut();
172-
let ret = ffi::g_key_file_get_keys(
173-
self.to_glib_none().0,
174-
group_name.to_glib_none().0,
175-
length.as_mut_ptr(),
176-
&mut error,
177-
);
178-
if error.is_null() {
179-
Ok((
180-
FromGlibPtrContainer::from_glib_full(ret),
181-
length.assume_init(),
182-
))
183-
} else {
184-
Err(from_glib_full(error))
185-
}
186-
}
187-
}
188-
189153
#[doc(alias = "g_key_file_get_locale_for_key")]
190154
#[doc(alias = "get_locale_for_key")]
191155
pub fn locale_for_key(

glib/src/key_file.rs

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
use std::{mem, path, ptr};
44

5-
use crate::{translate::*, Error, GString, KeyFile, KeyFileFlags};
5+
use crate::{translate::*, Error, GStrPtr, GString, KeyFile, KeyFileFlags, PtrSlice};
66

77
impl KeyFile {
88
#[doc(alias = "g_key_file_save_to_file")]
@@ -85,6 +85,39 @@ impl KeyFile {
8585
}
8686
}
8787

88+
#[doc(alias = "g_key_file_get_groups")]
89+
#[doc(alias = "get_groups")]
90+
pub fn groups(&self) -> PtrSlice<GStrPtr> {
91+
unsafe {
92+
let mut length = mem::MaybeUninit::uninit();
93+
let ret = ffi::g_key_file_get_groups(self.to_glib_none().0, length.as_mut_ptr());
94+
FromGlibContainer::from_glib_full_num(ret, length.assume_init() as _)
95+
}
96+
}
97+
98+
#[doc(alias = "g_key_file_get_keys")]
99+
#[doc(alias = "get_keys")]
100+
pub fn keys(&self, group_name: &str) -> Result<PtrSlice<GStrPtr>, crate::Error> {
101+
unsafe {
102+
let mut length = mem::MaybeUninit::uninit();
103+
let mut error = ptr::null_mut();
104+
let ret = ffi::g_key_file_get_keys(
105+
self.to_glib_none().0,
106+
group_name.to_glib_none().0,
107+
length.as_mut_ptr(),
108+
&mut error,
109+
);
110+
if error.is_null() {
111+
Ok(FromGlibContainer::from_glib_full_num(
112+
ret,
113+
length.assume_init() as _,
114+
))
115+
} else {
116+
Err(from_glib_full(error))
117+
}
118+
}
119+
}
120+
88121
#[doc(alias = "g_key_file_get_boolean")]
89122
#[doc(alias = "get_boolean")]
90123
pub fn boolean(&self, group_name: &str, key: &str) -> Result<bool, Error> {
@@ -167,7 +200,7 @@ impl KeyFile {
167200

168201
#[doc(alias = "g_key_file_get_string_list")]
169202
#[doc(alias = "get_string_list")]
170-
pub fn string_list(&self, group_name: &str, key: &str) -> Result<Vec<GString>, Error> {
203+
pub fn string_list(&self, group_name: &str, key: &str) -> Result<PtrSlice<GStrPtr>, Error> {
171204
unsafe {
172205
let mut length = mem::MaybeUninit::uninit();
173206
let mut error = ptr::null_mut();
@@ -223,7 +256,7 @@ impl KeyFile {
223256
group_name: &str,
224257
key: &str,
225258
locale: Option<&str>,
226-
) -> Result<Vec<GString>, Error> {
259+
) -> Result<PtrSlice<GStrPtr>, Error> {
227260
unsafe {
228261
let mut length = mem::MaybeUninit::uninit();
229262
let mut error = ptr::null_mut();

0 commit comments

Comments
 (0)