rust - Dealing with C's Null terminating pointer (ffi) -


I remember that the function is array_each but now it's excluded whether it is replaced by any other function was given? If not, how can I use the C pointer as a correlation array in an array?

  extern {fn testing () -> * MyList} # [repr (c)] struct MyList; Fn Main () {insecure} {list = test (); // want to redo through the list}}  

Use: extern {fn get_some_list (lane: * mut u32) - & gt; * Mut u32; } Fn Main () {use std :: slice; Unsafe {Give: U32 = 0; Let's ptr: * mut u32 = get_some_list (& amp; forgive lane); Thrust! (Ptr.is_null ()!); Let's see: & amp; [U32] = fragment :: from_raw_parts (ptr, as usize); For & amp; V. View.iter () {println! ("{}", V); The resultant slice can have a arbitrary lifetime (including 'static ), so be careful about securing that piece out.

(Note: Your original code uses some old syntax, which I have decided in this answer. For example, you can type const or mut after * now.)


Comments

Popular posts from this blog

java - Can't add JTree to JPanel of a JInternalFrame -

javascript - data.match(var) not working it seems -

javascript - How can I pause a jQuery .each() loop, while waiting for user input? -