Guest User

Untitled

a guest
Oct 20th, 2018
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.76 KB | None | 0 0
  1. use std::ffi::{CStr, FromBytesWithNulError};
  2. use std::os::raw::c_char;
  3.  
  4. fn main() { unsafe {
  5. let strings: Vec<String> = vec!["foo\0".to_string(), "bar\0".to_string()];
  6.  
  7. let result: Result<Vec<*const c_char>, FromBytesWithNulError> =
  8. strings.iter()
  9. .map(|s: &String|
  10. CStr::from_bytes_with_nul(s.as_bytes())
  11. .map(CStr::as_ptr))
  12. .collect();
  13.  
  14. let result: Vec<*const c_char> = result.unwrap();
  15.  
  16. let result: &[*const c_char] = &*result;
  17.  
  18. let result: *const *const c_char = result.as_ptr();
  19.  
  20. println!("{:?}", result);
  21.  
  22. let num_strings = strings.len();
  23. let mut current = result;
  24.  
  25. for _ in 0..num_strings {
  26. println!("{:?}", CStr::from_ptr(*current));
  27. current = current.offset(1);
  28. }
  29.  
  30. } }
Add Comment
Please, Sign In to add comment