Skip to content

Commit 7104471

Browse files
committed
gio: document the interaction of the Task result setter and getters
The three ways you can return a result from the task must be match in how you set and get the fields. Document this in the different functions and mark them as unsafe unconditionally to indicate that there is no way within the type system to ensure that you are using it safely.
1 parent e5b2118 commit 7104471

File tree

1 file changed

+46
-3
lines changed

1 file changed

+46
-3
lines changed

gio/src/task.rs

Lines changed: 46 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,13 @@ macro_rules! task_impl {
237237
unsafe { from_glib(ffi::g_task_return_error_if_cancelled(self.to_glib_none().0)) }
238238
}
239239

240+
// rustdoc-stripper-ignore-next
241+
/// Set the result of the task
242+
///
243+
/// # Safety
244+
///
245+
/// The value must be read with [`Task::propagate`],
246+
/// `g_task_propagate_value` or `g_task_propagate_pointer`.
240247
#[doc(alias = "g_task_return_value")]
241248
#[doc(alias = "g_task_return_pointer")]
242249
#[doc(alias = "g_task_return_error")]
@@ -270,6 +277,13 @@ macro_rules! task_impl {
270277
}
271278
}
272279

280+
// rustdoc-stripper-ignore-next
281+
/// Set the result of the task as a boolean
282+
///
283+
/// # Safety
284+
///
285+
/// The value must be read with [`Task::propagate_boolean`],
286+
/// or `g_task_propagate_boolean`.
273287
#[doc(alias = "g_task_return_boolean")]
274288
#[allow(unused_unsafe)]
275289
pub $($safety)? fn return_boolean_result(self, result: Result<bool, glib::Error>) {
@@ -279,6 +293,13 @@ macro_rules! task_impl {
279293
}
280294
}
281295

296+
// rustdoc-stripper-ignore-next
297+
/// Set the result of the task as an int
298+
///
299+
/// # Safety
300+
///
301+
/// The value must be read with [`Task::propagate_int`],
302+
/// or `g_task_propagate_int`.
282303
#[doc(alias = "g_task_return_int")]
283304
#[allow(unused_unsafe)]
284305
pub $($safety)? fn return_int_result(self, result: Result<isize, glib::Error>) {
@@ -289,10 +310,18 @@ macro_rules! task_impl {
289310
}
290311

291312

313+
// rustdoc-stripper-ignore-next
314+
/// Gets the result of the task and transfers ownership of it
315+
///
316+
/// # Safety
317+
///
318+
/// This must only be called once, and only if the result was set
319+
/// via [`Task::return_result`], `g_task_return_value` or
320+
/// `g_task_return_pointer`.
292321
#[doc(alias = "g_task_propagate_value")]
293322
#[doc(alias = "g_task_propagate_pointer")]
294323
#[allow(unused_unsafe)]
295-
pub $($safety)? fn propagate(self) -> Result<V, glib::Error> {
324+
pub unsafe fn propagate(self) -> Result<V, glib::Error> {
296325
let mut error = ptr::null_mut();
297326

298327
unsafe {
@@ -329,9 +358,16 @@ macro_rules! task_impl {
329358
}
330359
}
331360

361+
// rustdoc-stripper-ignore-next
362+
/// Gets the result of the task as a boolean, or the error
363+
///
364+
/// # Safety
365+
///
366+
/// This must only be called once, and only if the result was set
367+
/// via [`Task::return_boolean_result`], or `g_task_return_boolean`.
332368
#[doc(alias = "g_task_propagate_boolean")]
333369
#[allow(unused_unsafe)]
334-
pub $($safety)? fn propagate_boolean(self) -> Result<bool, glib::Error> {
370+
pub unsafe fn propagate_boolean(self) -> Result<bool, glib::Error> {
335371
let mut error = ptr::null_mut();
336372

337373
unsafe {
@@ -345,9 +381,16 @@ macro_rules! task_impl {
345381
}
346382
}
347383

384+
// rustdoc-stripper-ignore-next
385+
/// Gets the result of the task as an int, or the error
386+
///
387+
/// # Safety
388+
///
389+
/// This must only be called once, and only if the result was set
390+
/// via [`Task::return_int_result`], or `g_task_return_int`.
348391
#[doc(alias = "g_task_propagate_int")]
349392
#[allow(unused_unsafe)]
350-
pub $($safety)? fn propagate_int(self) -> Result<isize, glib::Error> {
393+
pub unsafe fn propagate_int(self) -> Result<isize, glib::Error> {
351394
let mut error = ptr::null_mut();
352395

353396
unsafe {

0 commit comments

Comments
 (0)