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
use std::ptr;

use ffi;
use glib::translate::*;
use {TargetEntry, TargetList};

impl TargetList {
    pub fn new(targets: &[TargetEntry]) -> Self {
        skip_assert_initialized!();
        let stashes: Vec<_> = targets
                                  .iter()
                                  .map(|e| e.to_glib_none())
                                  .collect();
        let mut t = Vec::with_capacity(stashes.len());
        for stash in &stashes {
            t.push(stash.0);
        }
        let t_ptr: *mut ffi::GtkTargetEntry = if t.len() > 0 {
            t.as_ptr() as *mut _
        } else {
            ptr::null_mut()
        };
        unsafe {
            from_glib_full(ffi::gtk_target_list_new(t_ptr, t.len() as u32))
        }
    }
}