Skip to main content

gtk/
target_list.rs

1// Take a look at the license at the top of the repository in the LICENSE file.
2
3use crate::TargetList;
4use crate::{TargetEntry, ffi};
5use glib::translate::*;
6use std::ptr;
7
8impl TargetList {
9    /// Creates a new [`TargetList`][crate::TargetList] from an array of [`TargetEntry`][crate::TargetEntry].
10    /// ## `targets`
11    /// Pointer to an array
12    ///  of [`TargetEntry`][crate::TargetEntry]
13    ///
14    /// # Returns
15    ///
16    /// the new [`TargetList`][crate::TargetList].
17    #[doc(alias = "gtk_target_list_new")]
18    pub fn new(targets: &[TargetEntry]) -> Self {
19        skip_assert_initialized!();
20        let stashes: Vec<_> = targets.iter().map(|e| e.to_glib_none()).collect();
21        let t: Vec<_> = stashes.iter().map(|stash| unsafe { *stash.0 }).collect();
22        let t_ptr: *mut ffi::GtkTargetEntry = if !t.is_empty() {
23            t.as_ptr() as *mut _
24        } else {
25            ptr::null_mut()
26        };
27        unsafe { from_glib_full(ffi::gtk_target_list_new(t_ptr, t.len() as u32)) }
28    }
29}