Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- use std::ffi::{CStr, FromBytesWithNulError};
- use std::os::raw::c_char;
- fn main() { unsafe {
- let strings: Vec<String> = vec!["foo\0".to_string(), "bar\0".to_string()];
- let result: Result<Vec<*const c_char>, FromBytesWithNulError> =
- strings.iter()
- .map(|s: &String|
- CStr::from_bytes_with_nul(s.as_bytes())
- .map(CStr::as_ptr))
- .collect();
- let result: Vec<*const c_char> = result.unwrap();
- let result: &[*const c_char] = &*result;
- let result: *const *const c_char = result.as_ptr();
- println!("{:?}", result);
- let num_strings = strings.len();
- let mut current = result;
- for _ in 0..num_strings {
- println!("{:?}", CStr::from_ptr(*current));
- current = current.offset(1);
- }
- } }
Add Comment
Please, Sign In to add comment